0

I used $scope but my array is not displayed. I came from knockoutjs and this is really strange.

http://jsfiddle.net/Yiping/4hu9eaoj/

angular.module('app', []).controller('T', function ($scope) {
    $scope.Test = "AAA";
    $scope.todos = [{
        text: 'learn angular',
        done: true
    }, {
        text: 'build an angular app',
        done: false
    }];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="app">
    <div ng-controller="T">{{Test}}
        <ul class="unstyled">
            <li ng-repeat="todo in T.todos"> <span>{{todo.text}}</span>
            </li>
        </ul>
    </div>
</div>

3 Answers 3

3

You don't need to explicitly refer to the controller in the ng-repeat call -- ng-repeat="todo in todos" is fine.

Updated fiddle: http://jsfiddle.net/b1dotx4y/1/

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but on AngularJS homepage they use "<li ng-repeat="todo in todoList.todos">"
In that case, todoList is a data object, not the controller name.
2

Change ng-repeat="todo in T.todos" to ng-repeat="todo in todos".

Comments

1

You can remove T.todos and use just todos in the view. Otherwise use controller as notation like T as t in ng-controller. Then use t.todos.

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.