标签:
修改 $rootScope
var $body = angular.element(document.body); // 1 var $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
标签:
原文地址:http://my.oschina.net/xzfx/blog/480160