从浏览器控制台调用 Angular 控制器函数 [英] Calling Angular Controller Function from Browser Console

查看:31
本文介绍了从浏览器控制台调用 Angular 控制器函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从控制台(Chrome 开发者工具控制台)调用 AngularJS 控制器功能?

Is it possible to call AngularJS controller function from console (Chrome Developer Tools console)?

例如

app.controller('AddCtrl', ['$scope', function ($scope) {



    $scope.save = function(){
        // do stuff here - call it from console
    };

}]);

推荐答案

是的,你只需要使用 angular.element 来获取一个在你的控制器范围内的元素:

Yes, you just need to use angular.element to get an element that's within the scope of your controller:

angular.element("yourElement").scope().save();

这篇关于从浏览器控制台调用 Angular 控制器函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆