I am using jQuery to add an ng-click event to an element using
$compile($('.selector'))($scope);
after inserting the ng-click attr (which works). However, I would like to be able to wrap this in a function and call it from a service.
Is this possible? I know $scope should not be used within a service so I am unsure as to how I would make this reusable across my application!
Any thoughts would be much appreciated!
Service
app.factory('testService', function() {
return {
switchTabs: function() {
//if condition is met switch tabs using jquery
$('.selector').attr('ng-click', 'doSomething()');
$compile($(.loginText))($scope);
}
}
});