angular.js - angularjs的$scope如何通过外部function操作?
高洛峰
高洛峰 2017-05-15 16:51:37
0
3
477

页面中同时引用了两个js文件,一个是angularjs的control,一个是常规js

control:

javascriptvar app = angular.module('app', []);
app.controller('ctrl', function($scope) {
    $scope.aaa = 1;
});

常规js:

javascript(function() {
    $scope.aaa = 2;  //有什么办法可以让这个实现?
})();

自己google解决了,http://www.cnblogs.com/czcz1024/p/3808345.html,浪费资源了,sorry。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
曾经蜡笔没有小新

Make good use of Google search. This kind of problem you often encounter is usually found on StackOverflow
How to access the angular $scope variable in browser's console?;

javascriptangular.element('[ng-controller=ctrl]').scope();
angular.element(document.querySelector('#id')).scope();
漂亮男人

The most rustic solution...window['scope']=$scope

曾经蜡笔没有小新

Write the angular controller in the function expression that is executed immediately:

    var app = angular.module('app', []);
    app.controller('ctrl', function($scope) {
        $scope.aaa = 1;
    });

Then introduce it into regular js

(function(app) {
    $scope.aaa = 2;  //有什么办法可以让这个实现?
})(app);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!