外部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.

复制代码

猜你喜欢

转载自blog.csdn.net/baby_code/article/details/84637639