有没有办法告诉 WebStorm AngularJS (v1) 组件 HTML 模板文件中的类型 $ctrl
是什么?
如果它是一个 JavaScript 文件,我可以使用 JSDoc,WebStorm 将使用该信息,并正确检测未使用的方法等。
WebStorm 的文档介绍了 Angular 插件,但该插件似乎不适用于较新的 AngularJS 组件,只能使用较旧的 ng-controller
样式。
最佳答案
根据release notes对于 WebStorm 2018.3,此问题已解决。
AngularJS improvements
We know that many people still use AngularJS. This is why we’ve fixed the top-voted problem affecting AngularJS support in WebStorm: completion and resolve for
$ctrl
, or for the name defined using thecontrollerAs
property in the template.
所以,如果您最近没有更新 WebStorm,我会先尝试一下。
否则,有一个很奇怪的方法来处理这个问题。您可以在模板的 ngInit
指令中执行类似的操作:
<div ng-init="$ctrl=$ctrl"></div>
这应该可以解决问题。但这可能是一个丑陋的解决方法。如果您最近没有更新,我会首先尝试更新。
关于javascript - 如何在 WebStorm 的 AngularJS 组件模板中输入提示 $ctrl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54532810/