I have made a directive which bind a click event with the element. On click I want to use a factory which makes an ajax call. How do I achieve this ? My code looks like this
angular.module('user')
.directive('activityFeed', function(userFactory, $http) {
return {
restrict: 'A',
link: function($scope, element, attrs) {
userFactory.getActivities();
element.bind('click', function() {
console.log("hello");
userFactory.getActivities();
})
}
}
})
First call which is outside the bind function works. Now when I click on the attribute it logs "hello" but it doesn't call getActivities()
.