1. 程式人生 > >外部javascript 方法修改 angularjs 中$rootScope和$scope

外部javascript 方法修改 angularjs 中$rootScope和$scope

【轉載】【轉載】【轉載】http://www.cnblogs.com/wangshuming/p/5569894.html

外部javascript 方法修改 angularjs 中 r o o t S c o

p e rootScope和 scope
修改 $rootScope
var $body = angular.element(document.body); // 1
var $rootScope = b o
d y . s c o p e ( ) .
body.scope().
root; // 2
r o o t S c o p e . rootScope. apply(function () { // 3
$rootScope.notesconfigs.outpath = path;
});
修改 $scope
var appElement = document.querySelector(’[ng-controller=mainController]’);//獲得繫結controllerdom節點
var s c o p e = a n g u l a r . e l e m e n t ( a p p E l e m e n t ) . s c o p e ( ) ; / / scope = angular.element(appElement).scope(); //獲得 scope物件
s c o p e . 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.

複製程式碼