全局控制器不使用AngularJS 1.3

时间:2014-10-29 21:04:39

标签: angularjs

以下代码在Angular 1.2中正常工作,但它不适用于1.3

我应该更改什么才能使其在1.3上运行?

<!DOCTYPE html>
<html data-ng-app="">

<head>
<title>MyApp</title>
</head>

<body>

<div class="wrapper" ng-controller="SimpleController">

    <div>Name:</div>
    <div>
        <input type="text" ng-model="filterword">
    </div>

    <ul>
        <li ng-repeat="person in contacts | filter: filterword | orderBy: 'name'" >{{ person.name }} lives in {{ person.city }}</li>
    </ul>

</div>

<script>
    var SimpleController = function($scope){
        $scope.contacts = [

            {name: 'Dave',
            city: 'Dresden'},

            {name:'John',
            city: 'Madrid'},

            {name:'Jane',
            city: 'Berlin'}
        ];
    }
</script>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我已经发现,正如this other thread所解释的那样,从版本1.3开始,不允许使用全局控制器,因为它们会产生非常混乱的代码。

More info