0
votes

Is there any way to tell WebStorm which type $ctrl is in an AngularJS (v1) component HTML template file?

If it were a JavaScript file, I could use JSDoc, and WebStorm would use that information, and would detect correctly unused methods, etc.

WebStorm's documentation tells about Angular plugin, but that plugin doesn't seem to work with newer AngularJS components, only with older ng-controller style.

1

1 Answers

1
votes

According to the release notes for WebStorm 2018.3, this was resolved.

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 the controllerAs property in the template.

So, if you have not updated WebStorm recently, I would first try that.

Otherwise, there is a hacky way to handle this. You could do something like this in an ngInit directive in your template:

<div ng-init="$ctrl=$ctrl"></div>        

That should do the trick. But it's probably an ugly workaround. I would first try updating if you haven't done so recently.