Cannot Print Attributes from Service Array to Index - RESOLVED


#1



I am not able to print the attributes of my suggestion.js service array to the index. How do i fix this problem. Thanks for the help.

Index.html

<!DOCTYPE html>
<html>
<head>
<title>Suggestion Box</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/
css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet"/>
 <script src="js/vendor/angular.min.js"></script>
</head>
<body ng-app="SuggestionBox">
    
    <div class="main" ng-controller="HomeController">
        <div class="container">
        <div ng-repeat="post in posts">
            <h1>{{post.title}}</h1>
            </div>
        </div>
     </div>

 
<!-- Modules -->
    <script src="js/app.js"></script>
 
<!-- Controllers -->
<script src="js/controllers/HomeController.js"></script>
 
<!-- Services -->
    <script src="js/services/suggestions.js"></script>
 
</body>
</html>

app.js

var app = angular.module('SuggestionBox', []);

HomeController.js

app.controller('HomeController', ['$scope', 'suggestions', function ($scope, suggestions) {
    $scope.posts = demoSuggestions.posts;
}]);

suggestions.js

app.factory('suggestions', [function(){
var demoSuggestions = {
posts: [
{
title: 'Free pizza at club meetings',
upvotes: 15,
comments: [],
},
{
title: 'End all club emails with Laffy Taffy jokes',
upvotes: 9,
comments: [],
},
{
title: 'Retrofit water fountain with Gatorade',
upvotes: 7,
comments: [],
},
{
title: 'Sing Bon Jovi\'s "Living on a Prayer" halfway through meetings',
upvotes: 3,
comments: [],
},
]
};
return demoSuggestions;
}]);

#2

I feel like the error is in the {{post.title}} within index, what should it be called?


#3

any possible advice on how i can make this work?


#4

Problem Resolved, the issue lied in my ng-repeat


#5

where was the actual problem??
i think i am facing the same problem, help me out too if you can


#6

you can use the above code. Only mistake I found is:
in HomeController.js, which should be:

app.controller('HomeController', [
    '$scope', 
    'suggestions', 
    function($scope, suggestions) {
        $scope.posts = suggestions.posts;
}]);