I have the data in the $scope, according to the scope classNames count, i require to create elements in the page with different data from the scope. how to it?
I am trying to add more no.of directive element, But i see only one output. and i am not able to pass the $scope data to it.
What is the correct way to do this?
Here is my try:
<div class="wrapper" ng-app="myApp">
<div class="helloWorld" ng-controller="hello">
<ul>
<li ng-repeat="item in items">
{{item.name}}
</li>
</ul>
<hello-world/> //added multiple times
<hello-world/>
<hello-world/>
<hello-world/>
<hello-world/>
</div>
</div>
var app = angular.module('myApp', []);
app.controller('hello', function ($scope) {
$scope.items = [
{name:'name1', className:'green'},
{name:'name2', className:'blue'},
{name:'name3', className:'brown'},
{name:'name4', className:'yellow'},
{name:'name5', className:'red'}
];
});
app.directive('helloWorld', function () {
return {
restrict: 'AE',
replace: 'true',
template: '<h3 class="{item.className}">Hello World!! from color of {{item.className}}</h3>',
scope: {
className: '@'
},
link : function ($scope, elem, attr) {
}
}
});
any one can help me to understand the concept and create the multiple instance of directive here?
Thanks in advance.