[英]Angular JS scope variable not working
学习使用angularJS,
我的index.html中有这个特定的代码。 动态键入在上部起作用,但注入无效。 可能出了什么问题?
代码:
<!DOCTYPE html>
<html>
<head>
<title>Test1</title>
</head>
<body ng-app="">
<!-- Dynamic Type -->
<input type="text" ng-model="name1" /><br>
<h1>Hello {{name1}}</h1>
<!-- End dynamic Type -->
<!-- Scope Injection begin-->
<div class="container" ng-controller="myController">
<input type="text" ng-model="naam" /><br>
<h3>Looping</h3>
<ul>
<li data-ng-repeat="cust in customerlist | filter:naam | orderBy:'city'"> {{cust.name | uppercase}} - {{cust.city}} </li>
</ul>
</div>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript">
function myController ($scope) {
$scope.customerlist = [
{name: 'Raj Bannerjee', city: 'Zaire'},
{name: 'Prasun Bannerjee', city: 'Udaipur'},
{name: 'Raj Malhotra', city: 'Dubai'},
{name: 'Prasun Joshi', city: 'Mumbai'}
];
}
</script>
</body>
</html>
从1.3版开始,使用全局控制器构造函数禁用了angular:
https://github.com/angular/angular.js/commit/3f2232b5a181512fac23775b1df4a6ebda67d018
除了简单的演示之外,对于控制器构造函数使用全局变量无济于事。 这将向
$controllerProvider
添加新方法以重新启用旧行为,但默认情况下禁用此功能。突破性变化:
$controller
将不再在window
上寻找控制器。 在控制器的window
上查看的旧行为最初旨在用于示例,演示和玩具应用程序。 我们发现允许全局控制器功能会鼓励不良做法,因此我们决定默认禁用此行为。
因此,您必须像这样重构它:
angular.module('app',[])
.controller('myController', ['$scope', function($scope) {
$scope.customerlist = [
{name: 'Raj Bannerjee', city: 'Zaire'},
{name: 'Prasun Bannerjee', city: 'Udaipur'},
{name: 'Raj Malhotra', city: 'Dubai'},
{name: 'Prasun Joshi', city: 'Mumbai'}
];
}]);
还请参考您的模块:
<body ng-app="app">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.