AngularJS load service then call controller and render

后端 未结 6 1420
生来不讨喜
生来不讨喜 2020-12-28 16:29

My problem is that i need a service loaded before the controller get called and the template get rendered. http://jsfiddle.net/g75XQ/2/

Html:

<
6条回答
  •  执笔经年
    2020-12-28 16:52

    The correct way to achieve that is using resolve property on routes definition: see http://docs.angularjs.org/api/ngRoute.$routeProvider

    then create and return a promise using the $q service; also use $http to make the request and on response, resolve the promise.

    That way, when route is resolved and controller is loaded, the result of the promise will be already available and not flickering will happen.

提交回复
热议问题