Angular $ Compile in a Service

时间:2015-10-23 11:42:45

标签: javascript jquery angularjs angular-services

我正在使用jQuery使用

向元素添加ng-click事件
    $compile($('.selector'))($scope);

插入ng-click attr(有效)。但是,我希望能够将它包装在一个函数中并从服务中调用它。

这可能吗?我知道$ scope不应该在服务中使用,所以我不确定如何在我的应用程序中重复使用它!

任何想法都会非常感激!

服务

app.factory('testService', function() {
   return {
      switchTabs: function() {
      //if condition is met switch tabs using jquery
       $('.selector').attr('ng-click', 'doSomething()');
       $compile($(.loginText))($scope);
       }
   }
});

0 个答案:

没有答案