gpt4 book ai didi

javascript - Angularjs 数据-ng- Controller

转载 作者:行者123 更新时间:2023-11-30 12:27:31 26 4
gpt4 key购买 nike

这是一个无法正常工作的简单内联 Controller 。我找不到错误。我已经用 ng-init 测试了这个并用 ng-repeat 打印出来,工作正常。使用 ng-controller,它不会。

<html data-ng-app>
<head>
<title></title>
</head>
<body data-ng-controller="SimpleController">
Name:
<br />
<input type="text" data-ng-model="name">
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:'city'">{{ cust.name}} ---- {{cust.city}}</li>
</ul>
<script src="Scripts/angular.min.js"></script>
<script>
function SimpleController($scope){
$scope.customers=[{name:'John Doe', city:'New York'},{name:'Jane Doe', city:'Melbourne'},{name:'Jack Daniels',city:'Atlanta'}];
}
</script>
</body>
</html>

最佳答案

您需要使用 javascript 启动应用

angular.module

对于您在 data-ng-app 中指定的应用名称

Working Fiddle

Javascript 代码:

angular.module("myApp", [])
.controller('SimpleController', function ($scope) {
$scope.customers = [{
name: 'John Doe',
city: 'New York'
}, {
name: 'Jane Doe',
city: 'Melbourne'
}, {
name: 'Jack Daniels',
city: 'Atlanta'
}];
});

关于javascript - Angularjs 数据-ng- Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28875575/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com