方法一
var element = angular.element($document.getElementById("app")); var controller = element.controller(); var scope = element.scope(); //调用方法 scope.sub1(); //如果需要重新绑定 scope.$apply(); //调用字段 scope.field1;
angular.element(domElement).scope() to get the current scope for the elementangular.element(domElement).injector() to get the current app injectorangular.element(domElement).controller() to get a hold of the ng-controller instance. 方法二:通过controller来获取app
var appElement = document.querySelector(‘[ng-controller=mainController]‘);
然后在获取$scope变量:
var $scope = angular.element(appElement).scope();
如果改变了其中的变量之后,需要在页面表现出来,还需要调用apply()方法:
$scope.$apply();
参考文章:https://segmentfault.com/a/1190000000747708https://www.cnblogs.com/CheeseZH/p/4515638.html
原文地址:https://www.cnblogs.com/miny-simp/p/9087510.html
时间: 2024-11-06 10:37:01