问题描述
我喜欢做手工引导(不使用的NG-应用指令)之前,使用角度的服务。有没有调用angular.bootstrap上的空白div来访问角度服务的一种方式?
下面的方法是有效的,但我不知道是否还有一个更直接的解决方案:
VAR元素= angular.element('< DIV>< / DIV>');
angular.bootstrap(元件);
变量$ =喷油element.injector();
变量$ HTTP = $ injector.get('$ HTTP');
变量$位置= $ injector.get('$位置');
有没有办法做到这一点不调用引导(或正从一个已自举元素注入),但有一个稍微更直接的方式这样做:
变量$ HTTP = angular.bootstrap()得到('$ HTTP')。
或者,如果你需要多个服务,你可以这样做:
angular.bootstrap()调用(函数($ HTTP,$位置){
$ http.get('/ foo的');
$ location.path('/ foo的');
});
I would like to use angular services before doing a manual bootstrap(the ng-app directive is not being used). Is there a way to access angular services without calling angular.bootstrap on an empty div?
The following approach works, but I'm wondering if there is a more direct solution:
var element = angular.element('<div></div>');
angular.bootstrap(element);
var $injector = element.injector();
var $http = $injector.get('$http');
var $location = $injector.get('$location');
There isn't a way to do it without calling bootstrap (or getting the injector from an already bootstrapped element), but there is a slightly more direct way of doing it:
var $http = angular.bootstrap().get('$http');
Or, if you need multiple services, you can do this:
angular.bootstrap().invoke(function($http, $location){
$http.get('/foo');
$location.path('/foo');
});
这篇关于手动引导前采用了棱角分明的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!