Angularjs 角度ng应用程序=";demoApp“;不适合我
我是个新手。到目前为止,代码运行良好,但当我使用ng app=“demoApp”或任何其他应用程序指令时,它似乎停止工作。它无法在控制器上绑定。我的看法是:Angularjs 角度ng应用程序=";demoApp“;不适合我,angularjs,Angularjs,我是个新手。到目前为止,代码运行良好,但当我使用ng app=“demoApp”或任何其他应用程序指令时,它似乎停止工作。它无法在控制器上绑定。我的看法是: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Learn AngularJS->Binding on the Controllers</title> <
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learn AngularJS->Binding on the Controllers</title>
</head>
<body>
<div class="container" ng-app="demoApp" data-ng-controller="simpleController">
<h3>Adding a simple Controller</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{cust.name}} - {{cust.city}}
</li>
</ul>
</div>
但是当我删除ng app=“demoApp”时,其他代码就可以正常工作了。我不明白的是ng应用程序指令对我不起作用。其他指令可以正常工作,但也可以停止工作。代码中的任何地方都使用app指令。我已经检查过,以确保应用程序指令在代码中没有使用两次,但根本没有成功。任何帮助,请,我可能会出错。我找不到任何错误。您的客户阵列中有一些错误。请复制粘贴下面的代码,然后重试 Html 您的数组定义错误 否:
{name:'John Smith',{city:'Kitale'}
是:
{姓名:'John Smith',城市:'Kitale'}
这是正在工作的插销:
因此,您的总体代码:
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="container" ng-app="demoApp" data-ng-controller="simpleController">
<h3>Adding a simple Controller</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{cust.name}} - {{cust.city}}
</li>
</ul>
</div>
<script>
var app = angular.module('demoApp', []);
app.controller('simpleController', function($scope) {
$scope.customers = [{
name: 'John Smith',
city: 'Kitale'
}, {
name: 'Jane Martins',
city: 'Bungoma'
}, {
name: 'Esther Williams',
city: 'Busia'
}, {
name: 'James Anthony',
city: 'Nakuru'
}, {
name: 'Irine seniorman',
city: 'Eldoret'
}, {
name: 'Agrey Ngoya',
city: 'Kitui'
}, {
name: 'Anne Chemos',
city: 'Bomet'
}, {
name: 'Zacheous Waweru',
city: 'Murang\'a'
}
];
});
</script>
</body>
</html>
添加一个简单的控制器
-
{{cust.name}-{{cust.city}
var app=angular.module('demoApp',[]);
app.controller('simpleController',函数($scope){
$scope.customers=[{
姓名:“约翰·史密斯”,
城市:“基特尔”
}, {
姓名:“简·马丁斯”,
城市:“邦戈马”
}, {
名字:“埃丝特·威廉姆斯”,
城市:“Busia”
}, {
姓名:“詹姆斯·安东尼”,
城市:“纳库鲁”
}, {
姓名:“Irine seniorman”,
城市:“埃尔多雷特”
}, {
姓名:“Agrey Ngoya”,
城市:“基图”
}, {
姓名:“安妮·凯莫斯”,
城市:“博米特”
}, {
名称:“Zacheous Waweru”,
城市:“Murang'a”
}
];
});
以html格式加载JS文件,如
查看下面的答案。也许这会对你有所帮助,你对$scope.customers的定义是错误的。你可以检查plunker,看看你能用你拥有的代码做些什么。向上投票并勾选正确,会让帮助者想要更多帮助:)非常感谢,它现在可以工作了。这只是你的问题我已经指出了。谢谢@Alex Rumba Nicked。这很有效。我真的很感谢你的帮助。很高兴我能帮上忙。
Adding a simple Controller
{{cust.name}} - {{cust.city}}
<body ng-app="demoApp">
<div class="container" ng-controller="simpleController">
<h3>Adding a simple Controller</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{cust.name}} - {{cust.city}}
</li>
</ul>
</div>
</body>
var app = angular.module('demoApp',[]);
app.controller('simpleController',['$scope', function($scope){
$scope.customers=[
{name:'John Smith',city:'Kitale'},
{name:'Jane Martins',city:'Bungoma'},
{name:'Esther Williams',city:'Busia'},
{name:'James Anthony',city:'Nakuru'},
{name:'Irine seniorman',city:'Eldoret'},
{name:'Agrey Ngoya',city:'Kitui'},
{name:'Anne Chemos',city:'Bomet'},
{name:'Zacheous Waweru',city:'Murang\'a'}
];
}]);
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="container" ng-app="demoApp" data-ng-controller="simpleController">
<h3>Adding a simple Controller</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{cust.name}} - {{cust.city}}
</li>
</ul>
</div>
<script>
var app = angular.module('demoApp', []);
app.controller('simpleController', function($scope) {
$scope.customers = [{
name: 'John Smith',
city: 'Kitale'
}, {
name: 'Jane Martins',
city: 'Bungoma'
}, {
name: 'Esther Williams',
city: 'Busia'
}, {
name: 'James Anthony',
city: 'Nakuru'
}, {
name: 'Irine seniorman',
city: 'Eldoret'
}, {
name: 'Agrey Ngoya',
city: 'Kitui'
}, {
name: 'Anne Chemos',
city: 'Bomet'
}, {
name: 'Zacheous Waweru',
city: 'Murang\'a'
}
];
});
</script>
</body>
</html>