我在爲Angularjs設置$ rootScope時遇到了問題。
下面是我的功能
App.controller('Controller',
function (UtilityService, $rootScope) {
var setSession = function() {
$rootScope.test = "yes"; // <-- I get this
UtilityService.getSession().success(
function() {
$rootScope.test = "No"; // <-- I don't get this How do I get/set this value?
});
};
setSession();
});
附加信息:
其中一個可能的工作方式是建立被多個控制器之間交互的服務。有沒有人知道如何通過返回http.get json對象的服務來做到這一點。
我無法在服務中實例化的控制器中獲取動態範圍。
我會用你的情況$範圍,無論是訪問‘測試’是在同一個控制器。 – 2015-02-11 20:11:13
那麼你可以設置$ rootScope爲$ scope?我需要訪問不同控制器中的「範圍」。 – Demodave 2015-02-11 20:27:52
可能希望使用服務在控制器之間共享數據,以免污染'$ rootScope'。但'$ rootScope'應該可以訪問。 – 2015-02-11 21:27:54