javascript - Uncaught Error: [$injector:modulerr] when using ng-repeat -
angular.module('app',[]) .controller('myctrl',function() { this.items = m; }); var m = { "india": "4", "england": "2", "brazil": "3", "uk": "1", "usa": "3", "syria": "2" };
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> <body> <h3>fifa mactch summary:</h3> <div ng-app='app' ng-controller="myctrl"> <ul> <li ng-repeat="(country,goals) in items">{{country}}: {{goals}}</li> </ul> </div> </body>
above code. when run it, got uncaught error [$injector:modulerr] error. can not figure out why error. me? appreciate that.
in order access angular properties in dom, need establish scope , inject $scope
dependency in controller, placing in function argument. need assign items
on scope object accessed in dom. work, should this. additionally, i'd avoid m
object floating outside controller. if using in 1 controller, i'd it's best keep information inside controller.
angular.module('app',[]) .controller('myctrl', ['$scope', function($scope) { $scope.items = { "india": "4", "england": "2", "brazil": "3", "uk": "1", "usa": "3", "syria": "2" }; }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> <body> <h3>fifa mactch summary:</h3> <div ng-app='app' ng-controller="myctrl"> <ul> <li ng-repeat="(country,goals) in items">{{country}}: {{goals}}</li> </ul> </div> </body>
Comments
Post a Comment