AngularJS ng-repeat示例无法正常工作

3

我目前在尝试一本AngularJS书中的示例,但它并没有正常工作。

在Batarang中出现了一个错误:

TypeError: Cannot read property '#' of undefined

这是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}
];
};

有什么想法是为什么这不起作用? 谢谢。

2
你忘记了 = $scope.countries = [ {name: '法国', population: 63.1}, {name: '英国', population: 61.8} ]; - Stephane Rolland
3个回答

12

你的代码中有一个错别字。在$scope.countries后面,你漏掉了=

使用:

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

演示版


2

look here:

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

function ctrl($scope) {

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

2

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接