1
我的指令是陣列屬性不解析來angularjs指令
angular.module('app').directive('authorDirective',authorDirective);
function authorDirective()
{
return {
restrict: 'E',
scope: {
Authors: '=',
details: '&',
name : '='
},
replace : true,
template:
'<table class="table"><thead>'+
'<tr><th>Name</th><th>Nationality</th><th>Dates</th></tr></thead>'+
'<tbody ng-repeat="model in Authors">'+
'<tr><td>{{model.Name}}</td><td>{{model.Nationality}}</td><td>{{model.Dates}}</td></tr>'+
'</tbody></table>'
};
}
控制器是
angular.module('app').controller('LabController',LabController);
function LabController()
{
var vm = this;
vm.Authors = [
{Name : "Mark Twain",Nationality : "American", Dates : "1885-1910"},
{Name : "A.A Miline",Nationality : "English", Dates : "1882-1956"},
{Name : "Charles Dickens",Nationality : "English", Dates : "1812-1870"},
{Name : "Jane Austen",Nationality : "English", Dates : "1775-1817"}
];
}
和HTML
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Directives</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
</head>
<body ng-controller="LabController as vm">
<div class="container">
<h1>Directives</h1>
<author-directive Authors="vm.Authors"></author-directive>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script src="./app/app.js"></script>
<script src="./app/LabController.js"></script>
<script src="./app/authorDirective.js"></script>
</body>
</html>
我試圖通過對象經由範圍屬性來指示。它正在工作。但是當我嘗試傳遞數組時,我不能。在瀏覽器控制檯中也沒有發現任何錯誤。我在這裏犯了什麼錯誤?預先感謝您的幫助。
謝謝你的男人。得到你的答案,並正確理解解釋,它解決了我的問題,如魅力。 –