AngularJS : Initialize service with asynchronous data

后端 未结 10 1741
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 03:09

I have an AngularJS service that I want to initialize with some asynchronous data. Something like this:

myModule.service(\'MyService\', function($http) {
            


        
10条回答
  •  长情又很酷
    2020-11-22 03:18

    You can use JSONP to asynchronously load service data. The JSONP request will be made during the initial page load and the results will be available before your application starts. This way you won't have to bloat your routing with redundant resolves.

    You html would look like this:

    
    
    
    

提交回复
热议问题