0

I have a html page with that is to call JSON data from a js file. The html is below:

<html>
<head>
    <meta charset="UTF-8">
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript" src="modules/app.js" ></script>

</script>
<title>
</title>

</head>
<body ng-app="albumsApp">
<div data-ng-controller="albumController">

    <ul data-ng-repeat="album in albums">
    <li>
      {{albums.title}}
    </li>
  </ul>  

</div>

</body>
</html>

The "app.js" file that it calls is below:

**

var albumsApp = angular.module ('albumsApp',[])
albumsApp.factory('albumFactory',function() {
return {
    getAlbums: function(){
        alert("test");
        return [{"artist": "Kid 606","title:":"Happiness"}];
        },
    };
});
albumsApp.controller ('albumController', function ($scope,albumFactory) {
$scope.albums = albumFactory.getAlbums();
});

** There are nor errors in the console when I run it, just nothing appears. The alert box "test" appears when I load the page so the function is getting called, it just doesn't display the JSON. Thank you for any replies.

2
  • 1
    Replace albums.title by album.title. And remove the trailing ':' from the "title:" key in the json Commented Jun 8, 2015 at 11:07
  • 2
    Use {{album.title}} instant of {{albums.title}} Commented Jun 8, 2015 at 11:07

2 Answers 2

1

change this:

{{albums.title}}

to

{{album.title}}
Sign up to request clarification or add additional context in comments.

Comments

0

It is OK now, thank you very much.

HTML is

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script type="text/javascript" src="modules/app.js" ></script>

</script>
<title>
</title>

</head>
<body ng-app="albumsApp">
<div data-ng-controller="albumController">

    <ul data-ng-repeat="album in albums">
    <li>
      Artist is "{{album.artist}} " and title is {{album.title}}

    </li>
  </ul>  

</div>

</body>
</html>

JS is

var albumsApp = angular.module ('albumsApp',[])

albumsApp.factory('albumFactory',function() {
return {
    getAlbums: function(){

        return [{"artist": "Kid 606","title":"Happiness"}];
        },
    };
});
albumsApp.controller ('albumController', function ($scope,albumFactory) {
$scope.albums = albumFactory.getAlbums();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.