2015-11-24 55 views
1

我有一個父級抽象狀態,它有一個從服務器獲取數據的解析器。ui-router State Children and Resolvers

然後通過ui-routers解析器繼承的性質,我可以訪問子狀態控制器中已解析的數據。

....controller('bla', function(resolvedData){.... 

一切是偉大的工作,但我在實施需要改變解決了數據的一部分的應用功能,並把它整個應用體現。

我假設解決的數據不是一個對象的引用,但它是服務返回正確的副本?這意味着,如果在父抽象控制器中,我更改了一部分解析數據,它將不會反映在子狀態中,因爲它們將查看數據服務中解析數據的原始副本。

回答

1

我假設所解析數據不是一個對象的引用,但它是一個什麼樣的服務返回正確的副本?

NO。 UI-Router傳遞返回的內容。如果它是一個參考,它將被所有消費者共享。

檢查代碼(沒有在所有提到的克隆 - 只是路過什麼解決) - state.js line 455

/** 

* .... 

* @param {object=} stateConfig.resolve 
* <a id='resolve'></a> 
* 
* An optional map&lt;string, function&gt; of dependencies which 
* should be injected into the controller. If any of these dependencies are promises, 
* the router will wait for them all to be resolved before the controller is instantiated. 
* If all the promises are resolved successfully, the $stateChangeSuccess event is fired 
* and the values of the resolved promises are injected into any controllers that reference them. 
* If any of the promises are rejected the $stateChangeError event is fired. 

* ... */ 
+1

這比我的回答更完整,這就是爲什麼我選擇了它。雖然結論是一樣的。 – austbot