javascript - Angular JS : ng-repeat doesn't work

标签 javascript angularjs

我是 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/

相关文章:

android - IOS : Cordova App Crash on Google Map api zoom in ios 11. 3 iphone x

javascript - Accordion 中的鼠标悬停和鼠标移出

javascript - localStorage使用优化

javascript - RegExp 树桩,应该很简单

javascript - 图像高度在附加元素上返回 0

AngularJs - 删除所有基于类名的指令

javascript - 以 Angular 绑定(bind)一次...然后在每个事件上再次绑定(bind)

JavaScript正则表达式验证时间格式 "09:15 AM"

Django、REST 和 Angular 路由

javascript - jQuery - 无法获取 td 的列号