I am beginner to angular custom directive. I just render two html template based on the controllers scope value using custom directive. After rendering the html ng-click="myclick()" event not working for both templates.
view.html
<div ng-controller = 'ctrl1'>
<div class="doc-list-wrapper" ></div>
</div>
<div ng-controller = 'ctrl2'>
<div class="doc-list-wrapper" ></div>
</div>
Template
<script type="text/ng-template" id="tmpl-doc-list-wrapper">
<ul>
<li ng-repeat="doc in docs" >
<a rel="external" ng-click="myclick()" >
<span >{{doc.stageName}}</span>
</a>
</li>
</ul>
</script>
Template Rendering
app.run(function ($templateCache) {
$templateCache.put(
'tmpl-doc-list-wrapper', jQuery('#tmpl-doc-list-wrapper').html());
});
My Directive
app.directive('docListWrapper', ['$timeout', function ($timeout) {
return {
restrict: 'C',
priority: 500,
replace: true,
templateUrl: 'tmpl-doc-list-wrapper',
scope: { docs: '=docs'},
link: function (scope, element, attrs) {
}
};
}])
Controllers
app.controller('ctrl1', function ($scope, $interval) {
$scope.docs = [{"doc":"http://google.com","stageName":"Project 1"},
{"doc":"http://google.com","stageName":"Project 2"},
{"doc":"http://google.com","stageName":"Project 3"},
{"doc":"http://google.com","stageName":"Project 4"},
{"doc":"http://google.com","stageName":"Project 5"},
{"doc":"http://google.com","stageName":"Project 6"},
{"doc":"http://google.com","stageName":"Project 7"},
{"doc":"http://google.com","stageName":"Project 8"}];
$scope.myclick = function(){
alert('clicked me ')
}
});
app.controller('ctrl2', function ($scope, $interval) {
$scope.docs = [{"doc":"http://google.com","stageName":"Unit 1"},
{"doc":"http://google.com","stageName":"Unit 2"},
{"doc":"http://google.com","stageName":"Unit 3"},
{"doc":"http://google.com","stageName":"Unit 4"},
{"doc":"http://google.com","stageName":"Unit 5"},
{"doc":"http://google.com","stageName":"Unit 6"},
{"doc":"http://google.com","stageName":"Unit 7"},
{"doc":"http://google.com","stageName":"Unit 8"}];
$scope.myclick = function(){
alert('clicked me ')
}
});