標籤:
修改 $rootScope
var $body = angular.element(document.body); // 1var $rootScope = $body.scope().$root; // 2$rootScope.$apply(function () { // 3 $rootScope.notesconfigs.outpath = path;});
2. 修改 $scope
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.
參考網站
1 http://stackoverflow.com/questions/24595460/how-to-access-update-rootscope-from-outside-angular
2 http://www.cnblogs.com/CheeseZH/p/4515638.html
外部javascript 方法修改 angularjs 中$rootScope和$scope