无法找出这个简单的Angular控制器的问题所在

Cannot figure out the issue with this simple Angular contoller

本文关键字:Angular 控制器 问题 简单      更新时间:2023-09-26

我是AngularJS的新手,有一个简单的控制器问题。有人能帮我吗?我不明白为什么SimpleController不能在这里工作!!我需要输入的文本框显示字段后,如{{name}}所示。基本上,它应该生成从SimpleController' where this list should be filtered by名称and ordered by预算'检索到的客户列表…但事实并非如此!下面是Html和JS代码:

<html ng-app="">
    <head>
       <title>My Angular with Simple Controller</title>
    </head>
    <body>
    <div ng-controller="SimpleController">
        Name: 
        <br />
        <input type="text" ng-model="name" /> {{name}}
        <br />
        <h3> Looping with ng-repeat & SimpleController</h3>
        <ul>
            <li ng-repeat="cust in customers | filter:name | orderBy:'budget'">
                 {{cust.name}} - {{cust.city}} - {{cust.budget}}
            </li>
        </ul>
    </div>
    <script src="angular.min.js"></script>
    <script>
        function SimpleController($scope) {
            $scope.customers = [
                {name: 'AAA', city:'cityAAA', budget:'500'},
                {name: 'BBB', city:'cityBBB', budget:'5000'},
                {name: 'ABC', city:'cityABC', budget:'6000'},
            ];
        }
    </script>
</body>
</html>    

不使用控制器(仅使用ng-init)

在添加angular模块时可以正常工作

var myApp = angular.module('myApp',[]);

小提琴