是否有可能将传递给类似于$ delegate.method的Angular服务的arke monkeypatch?

时间:2016-04-28 02:01:53

标签: angularjs

在我目前的Angular项目中,我一直在使用$ provide.decorator来对主应用程序下游的一些功能进行monkeypatch,这让我想到了一个我无法弄清楚的问题。假设您使用此技术在$ http.get之前添加“Bloop bloop”消息(忽略拦截器在这里会更好的一分钟):

$provide.decorator('$http', function ($delegate) {
   get = $delegate.get;

   $delegate.get = function () {
      // arguments passed to $http.get are accessible here
      console.log('Bloop bloop');
      return get.apply(this, arguments);
   }
   return $delegate;
}

我的问题是:如何访问传递给服务本身的参数?在这种情况下,可以直接调用$ http(),将'GET'作为方法属性。有没有办法进入那里,类似于如何进入任何服务或工厂方法,如上所述?

0 个答案:

没有答案