简体   繁体   English

用这个简单的Angular控制器无法解决问题

[英]Cannot figure out the issue with this simple Angular contoller

I am new to AngularJS and have a problem with a simple controller. 我是AngularJS的新手,并且对简单的控制器有疑问。 Can anyone help me with that? 有人可以帮我吗? I don't understand why the SimpleController does not work here!!! 我不明白为什么SimpleController在这里不起作用!!! I need the input of the text box be shown after the field as shown by {{name}} . 我需要在{{name}}所示字段之后显示文本框的输入。 And basically it should produce a list of customers retrieved from SimpleController' where this list should be filtered by name and ordered by budget`... But it does not! 基本上它应该产生从中检索客户的名单SimpleController' where this list should be filtered by的名字and ordered by budget` ......但事实并非如此! Here is the Html and JS code: 这是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>    

the scenario works fine without the use of controller ( by using only ng-init ) 该场景无需使用控制器即可正常工作(仅使用ng-init

Works fine when angular module is added. 添加角度模块后,效果很好。

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

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM