【转载】【转载】【转载】http://www.cnblogs.com/wangshuming/p/5569894.html
外部javascript 方法修改 angularjs 中
r
o
o
t
S
c
o
p
e
和
rootScope和
rootScope和scope
修改 $rootScope
var $body = angular.element(document.body); // 1
var $rootScope =
b
o
d
y
.
s
c
o
p
e
(
)
.
body.scope().
body.scope().root; // 2
r
o
o
t
S
c
o
p
e
.
rootScope.
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=angular.element(appElement).scope();//获得scope对象
s
c
o
p
e
.
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.
复制代码