代码之家  ›  专栏  ›  技术社区  ›  user310291

数据是angularjs中的保留关键字吗?

  •  0
  • user310291  · 技术社区  · 6 年前

    如果我使用 data in lst ,如果我 代替 data 具有 x ,那么数据是angularjs中的保留关键字吗?为什么?

    <script src="http://ajadata.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    
    <body ng-app='app1'>
      <div id='Grocery' ng-controller='Grocery'>
        <h3>Grocery List</h3>
        <div ng-repeat='data in lst'>
          <h4>{{data.item}}</h4>
        </div>
        <br>
    
        <p> enter item:
          <input type="text" ng-model='addItem' />
        </p>
        <button ng-click='addTolist(addItem)'>Add to list</button>
        <button ng-click='addTolist(addItem)'>Add to list</button>
        <h2>{{NoItemError}}</h2>
      </div>
      <!-- End of Grocery -->
      <script>
        var app1 = angular.module('app1', []);
        app1.controller('Grocery', function($scope) {
          $scope.lst = [{
              item: 'banana',
              needed: false
            },
            {
              item: 'apple',
              needed: false
            },
            {
              item: 'milk',
              needed: false
            },
            {
              item: 'tomato',
              needed: false
            },
            {
              item: 'juice',
              needed: false
            }
          ]
          $scope.addTolist = function(addItem) {
            if (!(addItem === undefined || addItem === '')) {
              $scope.lst.push({
                item: addItem,
                needed: false
              });
              $scope.NoItemError = '';
            } else {
              $scope.NoItemError = 'Please enter an item';
            }
          }
        });
      </script>
    </body>

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   Aleksey Solovey    6 年前

    在用另一个替换文本时,您破坏了AngularJS脚本的CDN URL。
    它变成了 http://ajadata.googleapis.com

    把它改成 http://ajax.googleapis.com

    以下是完整的脚本:

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

    下面是代码的一个工作示例:

    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    
    <body ng-app='app1'>
      <div id='Grocery' ng-controller='Grocery'>
        <h3>Grocery List</h3>
        <div ng-repeat='data in lst'>
          <h4>{{data.item}}</h4>
        </div>
        <br>
    
        <p> enter item:
          <input type="text" ng-model='addItem' />
        </p>
        <button ng-click='addTolist(addItem)'>Add to list</button>
        <button ng-click='addTolist(addItem)'>Add to list</button>
        <h2>{{NoItemError}}</h2>
      </div>
      <!-- End of Grocery -->
      <script>
        var app1 = angular.module('app1', []);
        app1.controller('Grocery', function($scope) {
          $scope.lst = [{
              item: 'banana',
              needed: false
            },
            {
              item: 'apple',
              needed: false
            },
            {
              item: 'milk',
              needed: false
            },
            {
              item: 'tomato',
              needed: false
            },
            {
              item: 'juice',
              needed: false
            }
          ]
          $scope.addTolist = function(addItem) {
            if (!(addItem === undefined || addItem === '')) {
              $scope.lst.push({
                item: addItem,
                needed: false
              });
              $scope.NoItemError = '';
            } else {
              $scope.NoItemError = 'Please enter an item';
            }
          }
        });
      </script>
    </body>


    在英语中,大多数保留词都是从 $ ,例如 $index $id 等等。