我目前正在尝试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}
];
};
为什么这不起作用的任何想法? 感谢
答案 0 :(得分:13)
您的代码中有拼写错误。您在=
$scope.countries
使用
$scope.countries = [
{name: 'France', population: 63.1},
{name: 'United Kingdom', population: 61.8}
];
答案 1 :(得分:2)
您忘记了=
$scope.countries = [ {name: 'France', population: 63.1}, {name: 'United Kingdom', population: 61.8} ];
答案 2 :(得分:2)
看这里:
http://jsfiddle.net/konan/xaAxs/
function ctrl($scope) {
$scope.population = 7000;
$scope.countries = [
{name: 'France', population: 63.1},
{name: 'United Kingdom', population: 61.8}
];
};