在我当前的应用程序中,我已经从 jQuery 调用了许多 AngularJS Controller 函数,但我刚刚开始使用 strict-di
指令,现在它给了我一个错误 angular().element()
没有定义这样的东西。
我在 Angular 网站和 StackOverflow 上搜索了太多关于这个问题的信息,但没有找到任何解决方案,我有 30-40 个 Controller ,总之我从 jQuery 调用函数,所以我无法更改它是否有任何解决方案保留我的所有代码并使用 strict-di
的方法?
还使用:
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
并在以下位置收到未定义的错误:
var myVar = angular.element(document.getElementById('ControllerID')).scope().FunctionName();
TIA
最佳答案
我不认为 strict-di
是你的问题。
根据scope()的文档 - https://docs.angularjs.org/api/ng/function/angular.element > jQuery/jqLite 额外功能 > 方法 >scope()
...Requires Debug Data to be enabled.
你的
$compileProvider.debugInfoEnabled(false);
禁用调试数据,因此 angular.element(document.getElementById('ControllerID')) 上的scope()返回未定义。
尝试设置
$compileProvider.debugInfoEnabled(true);
关于javascript - 如果使用严格 DI,如何从 jQuery 调用 Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31137598/