【问题标题】:AngularJS ng-repeat example not workingAngularJS ng-repeat 示例不起作用
【发布时间】:2013-10-30 16:40:48
【问题描述】:

我目前正在尝试 AngularJS 书中的一个示例,但它不起作用。 我收到 Batarang 的错误提示:

ypeError: 无法读取未定义的属性“#”

这是 HTML:

<body ng-app>

<h1>Countries</h1>

<ul ng-controller="WorldCtrl">
    <li ng-repeat="country in countries">
        {{country.name}} has population of {{country.population}}
    </li>
    <hr>
World's population: {{population}} millions
</ul>

</body>

还有我的 js

var WorldCtrl = function ($scope) {
$scope.population = 7000;
$scope.countries [
    {name: 'France', population: 63.1},
    {name: 'United Kingdom', population: 61.8}
];
};

任何想法为什么这不起作用? 谢谢

【问题讨论】:

  • 你忘了= $scope.countries = [ {name: 'France', population: 63.1}, {name: 'United Kingdom', population: 61.8} ];

标签: javascript angularjs ng-repeat


【解决方案1】:

您的代码中有错字。 $scope.countries之后你错过了=

使用

$scope.countries = [
    {name: 'France', population: 63.1},
    {name: 'United Kingdom', population: 61.8}
];

Working Demo

【讨论】:

    【解决方案2】:

    您在$scope.countries = [ {name: 'France', population: 63.1}, {name: 'United Kingdom', population: 61.8} ]; 中忘记了=

    【讨论】:

      【解决方案3】:

      看这里:

      http://jsfiddle.net/konan/xaAxs/

      function ctrl($scope) {
      
          $scope.population = 7000;
          $scope.countries = [
              {name: 'France', population: 63.1},
              {name: 'United Kingdom', population: 61.8}
          ];
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-27
        • 1970-01-01
        • 2023-03-28
        相关资源
        最近更新 更多