Angular.js:如何在模块中创建控制器?

hh5*_*188 12 controls module angularjs

我想在使用模块时定义一个控制器:

angular.module('todoList', [], function () {

}).controller('myCtrl', function ($scope) {
    return function ($scope) {
        $scope.todos = [
            {
                text: "Hello"
            }, {
                text: "World"
            }
        ]
    }

})
Run Code Online (Sandbox Code Playgroud)

然后我想使用模块和ccontroller:

<div ng-controller="myCtrl" ng-app="todoList">  
        <li ng-repeat="todo in todos">
            <span>{{todo.text}}</span>
        </li>>
</div>
Run Code Online (Sandbox Code Playgroud)

但它没有渲染,我的代码有什么问题?

Aru*_*hny 15

您的控制器错误,无需返回功能.

angular.module('todoList', [], function () {

}).controller('myCtrl', function ($scope) {

        $scope.todos = [
            {
                text: "Hello"
            }, {
                text: "World"
            }
        ]
})
Run Code Online (Sandbox Code Playgroud)

演示:Plunker