我是 Angular JS 的新手。这是我第一次通过观看教程使用 Angular JS 编写一些代码。但在该视频教程中,代码工作正常,但我的代码无法工作。我的网页显示空白页。
index.html
<!DOCTYPE html>
<html ng-app xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MTG Browser</title>
<link href="index.css" rel="stylesheet" />
<script src="angular.min.js"></script>
<script src="CardsController.js"></script>
</head>
<body ng-controller="cardsListController">
<div id="cardsList">
<div ng-repeat="card in cards" class="cardItem">
Card {{card.id}}
</div>
</div>
</body>
</html>
还有CardsController.js
var cardsListController = function ($scope) {
$scope.cards = [{ id: 1 }, { id: 2 }];
};
请有人解释一下为什么代码不起作用?
最佳答案
HTML
<html ng-app="myApp">
<head>
<title>MTG Browser</title>
<link href="index.css" rel="stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="cardsListController">
<div id="cardsList">
<div ng-repeat="card in cards" class="cardItem">
Card {{card.id}}
</div>
</div>
</body>
</html>
和 .js
angular.module('myApp', []);
var cardsListController = function ($scope) {
$scope.cards = [{ id: 1 }, { id: 2 }];
};
关于javascript - Angular JS : ng-repeat doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31115770/