[英]binding data not working in angularjs
I am a new with AngularJS, and I am trying to bind data to the form controller, but it is not working. 我是AngularJS的新手,并且尝试将数据绑定到表单控制器,但无法正常工作。
<div ng-app="myapp" data-ng-controller="simpleContr">
<ul>
<li data-ng-repeat="user in users">
{{ user.name }}
</li>
</ul>
</div>
angular.module('myapp', []).controller('simpleContr', function($scope) {
$scope.users = [
{ name:'Ashraf', city:'Cairo'},
{ name:'Ali', city:'Assuit'},
{ name:'Mohammed', city:'Qena'}
];
});
The following works below, because the javascript is inserted into the head of the output document. 由于javascript插入了输出文档的开头,因此下面的工作在下面。
<head>
<head>
<head>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript">
// Your controller code...
</script>
</head>
angular.module('myapp', []).controller('simpleContr', function ($scope) { $scope.users = [{ name: 'Ashraf', city: 'Cairo' }, { name: 'Ali', city: 'Assuit' }, { name: 'Mohammed', city: 'Qena' }]; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp" data-ng-controller="simpleContr"> <ul> <li data-ng-repeat="user in users">{{ user.name }}</li> </ul> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.