我是AngularJS的新手。试图从youtube上的教程中学习。我写的是教练写的相同的代码。但不幸的是我的一个不工作。我为分享这种愚蠢的问题而道歉,但我真的很惊讶看到相同的代码对我不起作用。提前谢谢。
<body data-ng-app="">
<div data-ng-controller="SimpleController">
<ul>
<li data-ng-repeat="cust in Customers">
{{cust.Name}}
</li>
</ul>
</div>
<script src="../Scripts/angular.js"></script>
<script>
function SimpleController($scope) {
$scope.Customers = [
{ Name: "Chanchal", City: "Dhaka" },
{ Name: "Masud", City: "Jessore" },
{ Name: "Humayun", City: "Barisal" }
];
}
</script>
答案 0 :(得分:1)
如果您使用1.3以下的角度版本,它应该可以使用,请点击此处
<!DOCTYPE html>
<html>
<head>
<script src="https://code.angularjs.org/1.2.0/angular.js"></script>
</head>
<body data-ng-app>
<div data-ng-controller="SimpleController">
<ul>
<li data-ng-repeat="cust in Customers">
{{cust.Name}}
</li>
</ul>
</div>
<script>
function SimpleController($scope) { $scope.Customers = [ { Name: "Chanchal", City: "Dhaka" }, { Name: "Masud", City: "Jessore" }, { Name: "Humayun", City: "Barisal" } ]; }
</script>
</body>
</html>
&#13;
答案 1 :(得分:0)
你必须引导角度应用程序。
var myApp = angular.module(&#39; myApp&#39;,[]);
<script>
var myApp = angular.module('myApp',[]);
function SimpleController($scope) {
$scope.Customers = [
{ Name: "Chanchal", City: "Dhaka" },
{ Name: "Masud", City: "Jessore" },
{ Name: "Humayun", City: "Barisal" }
];
}
</script>
和
<body data-ng-app="myApp">
答案 2 :(得分:0)
你不能在角度上拥有全局控制器(除非你允许全局控制器使用controllerProvider
)
function SimpleController($scope) {
$scope.Customers = [
{ Name: "Chanchal", City: "Dhaka" },
{ Name: "Masud", City: "Jessore" },
{ Name: "Humayun", City: "Barisal" }
];
}
SimpleController.$inject = ['$scope'];
angular.module('myApp', []).controller('SimpleController', SimpleController);
和HTML,
<body ng-app="myApp">