我目前正在尝试从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
使用

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

Working Demo

07-24 09:52
查看更多