我在這方面還是比較新的,但是我遇到問題讓我的ng-repeat輸出book.review和book.stars。任何人都可以指出什麼是錯的?即使我把東西像只是一個字的NG-重複例如像ng-repeat不輸出數組結果
的測試字測試字從來沒有呈現在屏幕上。
的index.html
<!DOCTYPE html>
<html ng-app="DirectivesTest">
<head>
<title>Directives Practice</title>
<link rel="stylesheet" href="app.css">
<script src="bower_components/angular/angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<div id="header">
The #1 Book Review Site With Only 6 Books!
</div>
<div class="container">
<div class="row">
<div class="col-md-4">
<div ng-controller="BookController">
<div class="test" ng-repeat="book in books">
{{book.review}}
{{book.stars}}
</div>
</div>
</div>
</div>
</div>
<book-reviews></book-reviews>
</body>
</html>
app.js
var app = angular.module('DirectivesTest', []);
app.directive('bookReviews', function(){
return {
restrict: 'E',
templateUrl: 'book-reviews.html',
controller: 'BookController' //controller function
}; //end return
}) //end directive
app.controller("BookController", [ '$scope', function($scope){
$scope.books = [{
$scope.title: "Harry Potter and the Sorcerer's Stone",
$scope.description: "Harry Potter has no idea how famoushe is. That's because he's being raised by his miserable aunt and uncle who are terrified Harry will learn that he's really a wizard, just as his parents were. But everything changes when Harry is summoned to attend an infamous school for wizards, and he begins to discover some clues about his illustrious birthright. From the surprising way he is greeted by a lovable giant, to the unique curriculum and colorful faculty at his unusual school, Harry finds himself drawn deep inside a mystical world he never knew existed and closer to his own noble destiny.",
$scope.review: [
{
$scope.stars: 5,
$scope.body: "I love this book!",
$scope.author: "[email protected]",
$scope.createdOn: 42434343
},
{
$scope.stars: 4,
$scope.body: "It was pretty good. A little long though",
$scope.author: "[email protected]",
$scope.createdOn: 42434343
},
{
$scope.stars: 5,
$scope.body: "It's the best book I've ever read.",
$scope.author: "[email protected]",
$scope.reatedOn: 454535543
}
]
}];
}])
你需要存儲'在'$ scope' books',如果你想從我更新視圖 – rob