AngularJS UI Router using resolved dependency in factory / service

后端 未结 3 1314
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-09 15:04

I have a UI Router defined something like this (trimmed for simplicity):

    $stateProvider
        .state(\'someState\', {
            resolve: {
                       


        
3条回答
  •  庸人自扰
    2021-02-09 15:37

    You cannot use the resolved values in services or factories, only in the controller that belongs to the same state as the resolved values. Services and factories are singletons and controllers are newly instantiated for (in this case) a state or anywhere else where ng-controller is used.

    The instantiation happens with the $controller service that is capable of injecting objects that belong only to that controller. Services and factories do not have this capability.

提交回复
热议问题