How should I about calling a directive's function from a html page such as index, using ng-click? Here's my directive's code:
$scope.moreText = function() {
$(".showMore").append(lastPart);
};
html:
<a ng-click='moreText()' class='showMore' href='#'>... show more</a>
My problem is that moreText() isn't being called when clicked. I understand that it's not the right $scope. but how do I access it?
Update:
angular.module('myapp').controller('FormTestCtrl', ['$scope', '$timeout', '$window',
function($scope, $timeout, $window) {
$scope.moreText = function() {
console.log("more text function***************");
$(".showMore").append(lastPart);
};
}
]);
Update: #2
Here is most of the directive:
angular.module('myapp').directive('tooltip', function($window, $timeout) {
return {
restrict: 'A',
replace: false,
scope: {
},
link: function ($scope, element, attrs, $parse, $timeout) {
$scope.moreText = function() {};
$scope.sb = false;
var tooltext = attrs.tooltip;
...
if (tooltext.length > 10){
var firstPart = tooltext.substring(10, 0);
var lastPart = tooltext.substring(11, tooltext.length);
tooltext = firstPart + "<a ng-click='moreText()' class='showMore' href='#'>... show more</a>";
}
$scope.tipText = function(){
element.append("<div class='tooltip'>"+tooltext+"</div>");
};
$scope.moreText = function() {
console.log("more text function***************");
$(".showMore").append(lastPart);
};
}
}
});
$scope.moreText?$scopebecause my html isn't inside the same$scopeas my$scope.moreTextfunction. So how can I go about accessing my moreText function from my index.html page?