My directive is
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></td><td></td><td></td></tr>'+
'</tbody></table>'
};
}
Controller is
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"}
];
}
and the 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>
I tried to pass object via scope attribute to directive. It was working. But when I try to pass array I can’t. Didn’t find any error in browser console also. What Wrong did I make here? Thanks in advance for helping.
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/22/array-attribute-not-parsing-to-angularjs-directive/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment