Using angular services before manual bootstrap

前端 未结 1 1058
不知归路
不知归路 2021-01-13 05:25

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 angu

相关标签:
1条回答
  • 2021-01-13 06:23

    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');
    });
    
    0 讨论(0)
提交回复
热议问题