0

I am trying to load some content using ng-repeat with Angular.js. I set up a controller which will create an array, and corresponding HTML uses ng-repeat to display all elements in the array.

HTML:

<div class="list-group" ng-controller="MainController as ctrl">
<p class="list-group-item cat" ng-repeat="element in ctrl.current_articles">{{ element }}</p>
</div>

JS:

angular.module('newsclassifier', [])

.controller('MainController', ['$http', function($http){
  var self = this;
  self.current_articles = [1,2,3,4,5];

}]);

Now on running this code, I am able to see that rows for 5 elements are being created in the corresponding div. However, no content is displayed. I tried using even the $scope syntax, but to no difference. I am running version 1.4.8 of Angular.js. Is there something amiss here?

1 Answer 1

3

There is a typo in your markup.

ng-controller="ctrl as MainController"

should be

ng-controller="MainController as ctrl"
Sign up to request clarification or add additional context in comments.

6 Comments

oh that was a typo. Not the actual problem though. Updated the question with the changes. Something else might be the problem
@SaurabhSood Did you get any errors in the console?
@SaurabhSood yep, it works fine, here is plunker
Looks to be working in the Plunker. However when I put it in my code, it stops working
Doesn't seem to be any errors. In fact, I can see that 5 rows are being created. Just that there is no content. Even inspecting doesn't show any data.
|

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.