我是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'}
];
});
答案 0 :(得分:0)
以下工作如下,因为javascript被插入到输出文档的头部。
<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>