gpt4 book ai didi

javascript - AngularJS 表达式未被处理

转载 作者:行者123 更新时间:2023-11-30 11:44:13 27 4
gpt4 key购买 nike

当我尝试在浏览器上查看 Angular 表达式时,我无法弄清楚为什么不显示它们。我正在尝试将 ng-repeat 嵌入到无序列表中,但是 html 显示为:

{{country.name}}

{{city.name}}

这是我的:

<!doctype html>
<html>
<head>
<script src="Scripts\angular.js"></script>
<script src="Scripts\script.js"></script>
</head>
<body ng-app="myModule" style="font-family:Arial">
<div ng-controller="myController">
<ul>
<li ng-repeat="country in countries">
{{country.name}}
<ul>
<li ng-repeat="city in country.cities">
{{city.name}}
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>




var myApp = angular
.module("myModule", [])
.controller("myController", function($scope) {
var countries = [
{
name: "UK",
cities: [
{ name: "London" },
{ name: "Manchester" },
{ name: "Portsmouth" }
]
},
{
name: "USA",
cities: [
{ name: "New York" },
{ name: "Trenton" },
{ name: "Philidelphia" }
]
},
{
name: "Poland"
cities: [
{ name: "Warsaw" },
{ name: "Poznan" },
{ name: "Lodz" }
]
}
];
$scope.countries = countries;
});

最佳答案

你失踪了,在波兰之后

 name: "Poland"

解决这个问题,一切都应该没问题

var myApp = angular.module("myModule", []).controller("myController", function($scope) {


var countries = [{
name: "UK",
cities: [{
name: "London"
}, {
name: "Manchester"
}, {
name: "Portsmouth"
}]
}, {
name: "USA",
cities: [{
name: "New York"
}, {
name: "Trenton"
}, {
name: "Philidelphia"
}]
}, {
name: "Poland",
cities: [{
name: "Warsaw"
}, {
name: "Poznan"
}, {
name: "Lodz"
}]
}];
$scope.countries = countries;
});
<!doctype html>
<html>

<head>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>

</head>

<body ng-app="myModule" style="font-family:Arial">
<div ng-controller="myController">
<ul>
<li ng-repeat="country in countries">
{{country.name}}
<ul>
<li ng-repeat="city in country.cities">
{{city.name}}
</li>
</ul>
</li>
</ul>
</div>
</body>

</html>

关于javascript - AngularJS 表达式未被处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41550762/

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