简体   繁体   English

绑定数据在angularjs中不起作用

[英]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的新手,并且尝试将数据绑定到表单控制器,但无法正常工作。

HTML 的HTML

<div ng-app="myapp"  data-ng-controller="simpleContr">
    <ul>
        <li data-ng-repeat="user in users">
            {{ user.name }}
        </li>
    </ul>
</div>   

AngularJS AngularJS

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插入了输出文档的开头,因此下面的工作在下面。

How to structure the <head> 如何构造<head>

<head>
    <script type="text/javascript" src="angular.js"></script>

    <script type="text/javascript">
        // Your controller code...
    </script>
</head>

Working snippet 工作片段

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM