I want define a controller when use module:
angular.module('todoList', [], function () {
}).controller('myCtrl', function ($scope) {
return function ($scope) {
$scope.todos = [
{
text: "Hello"
}, {
text: "World"
}
]
}
})
then I want use the module and the ccontroller:
<div ng-controller="myCtrl" ng-app="todoList">
<li ng-repeat="todo in todos">
<span>{{todo.text}}</span>
</li>>
</div>
but it render nothing, what's wrong with my code?
http://docs.angularjs.org/guide/controller
var myApp = angular.module('myApp',[]);
myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
Your controller is wrong, there is no need to have a return function.
angular.module('todoList', [], function () {
}).controller('myCtrl', function ($scope) {
$scope.todos = [
{
text: "Hello"
}, {
text: "World"
}
]
})
Demo: Plunker
var myName1=angular.module("myName",[]);
myName1.controller("nameInfo",["$scope",function($scope){
$scope.name="Rajnish";
$scope.address="Delhi";
}
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With