In angular js, I have constructed a tree for navigation. On click of the left nav links, I want to load data (it is static data, I have to read it form a json file and display) in the page. However, I am not able to make the function call on click of the leftnav.
HTML Code:
<div class="collapse-toggler"><collection collection='tasks'></collection</div>
<div id="articleContent">{{articleContent}}</div>
JS File:
app.directive('collection', function() {
return {
restrict: "E",
replace: true,
scope: {
collection: '=',
articleData: '=',
articleContent: '='
},
template: "<ul><member ng-repeat='member in collection' member='member' article-data='articleData' article-content='articleContent'></member></ul>"
}
});
app.directive('member', function($compile) {
return {
restrict: "A",
replace: true,
scope: {
member: '=',
articleData: '=',
articleContent: '='
},
template: "<div><li><a ng-href='#' ng-click='getArticleContent()'>{{member.title}}</a></li></div>",
link: function(scope, element, attrs) {
scope.getArticleContent = function() {
scope.articleContent = articleData[0].getArticleResponse.articleDetail.articleContent;
}
if (angular.isArray(scope.member.tocItem)) {
if (scope.member.hasChildren == "true") {
for (var i = 0; i < scope.member.tocItem.length; i++) {
if (scope.member.tocItem.title) {
scope.member.tocItem.title.hide = true;
}
}
}
element.append("<collection collection='member.tocItem'></collection>");
$compile(element.contents())(scope)
}
}
}
});
app.controller('apdController', function($scope, getTocService) {
var sampdata = getTocService.getToc('bookid-1');
$scope.tasks =sampdata;
$scope.getArticleContent = function(){
alert('hello');
$scope.articleContent = articleData[0].getArticleResponse.articleDetail.articleContent;
};
});
I was able to set articleContent data in link function but not able to pass back to html. When I tried to set that in controller, I am not able to make function call.
There is no error in browser console. I am not getting my mistake. Can someone please point it out?
memberbut where you are including it. ??