angularjs 中的控制器功能?

controller function in angularjs?

我是 angular js 新手

控制器在我的代码中无法正常工作

我正在尝试运行遵循代码

<!DOCTYPE html>
<html data-ng-app >
<head>
    <title>Using AngularJS Directives and Data binding</title>
</head>
<body>

    name 
    <br />

    <div data-ng-controller="SimpleController">
    <input type="text"  data-ng-model="name"/>{{name}}

    <ul>
    <li data-ng-repeat="cust in customers | filter:name | orderBy:city"> {{cust.name | uppercase}}-{{cust.city | lowercase}} </li>
    </ul>
    </div>

    <script src= "angular/angular.min.js"></script>

    <script>

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

        demoApp.controller('SimpleController', function($scope){
        $scope.customers=[
        {name:'John Smith', city:'kashipur'},
        {name:'John fds' , city:'san francisko'},
        { name:'shubham', city:'giarhineg'},
        {name:'batra', city:'world'}];
        });
    </script>
</body>
</html>
</html>

但它没有给出想要的输出。

如果我做错了什么请告诉我。

您缺少在 ng-app 指令中添加值,该指令告诉 angular 到 运行 demoApp 页面上的模块。

ng-app="demoApp"

您应该添加应用的名称。

ng-app="demoApp"

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

  demoApp.controller('SimpleController', function($scope) {
    $scope.customers = [{
      name: 'John Smith',
      city: 'kashipur'
    }, {
      name: 'John fds',
      city: 'san francisko'
    }, {
      name: 'shubham',
      city: 'giarhineg'
    }, {
      name: 'batra',
      city: 'world'
    }];
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="demoApp">
  name
  <br />

  <div data-ng-controller="SimpleController">
    <input type="text" data-ng-model="name" />{{name}}

    <ul>
      <li data-ng-repeat="cust in customers | filter:name | orderBy:city">{{cust.name | uppercase}}-{{cust.city | lowercase}}</li>
    </ul>
  </div>
</div>