gpt4 book ai didi

javascript - AngularJS ng-repeat 示例不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:47 24 4
gpt4 key购买 nike

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

关于javascript - AngularJS ng-repeat 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688798/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com