修改 $rootScopehtml
var $body = angular.element(document.body); // 1 var $rootScope = $body.scope().$root; // 2 $rootScope.$apply(function () { // 3 $rootScope.notesconfigs.outpath = path; });
2. 修改 $scopeapp
var appElement = document.querySelector('[ng-controller=mainController]');//得到綁定controllerdom節點 var $scope = angular.element(appElement).scope(); //得到$scope對象 $scope.$apply();//刷新數據
獲取當前元素的$socpe: angular.element(domElement).scope() to get the current scope for the element
獲取當前app的injector: angular.element(domElement).injector() to get the current app injector
獲取當前元素的controller:angular.element(domElement).controller() to get a hold of the ng-controller instance.dom
參考網站ide
1 http://stackoverflow.com/questions/24595460/how-to-access-update-rootscope-from-outside-angular 網站
2 http://www.cnblogs.com/CheeseZH/p/4515638.htmlspa