Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template: unresolved variable or type $ctrl

How to tell PhpStorm/WebStorm that $ctrl in a template is known and also help it decide the controller it belongs to (maybe using jsdoc)?

I create components in this manner in Angular 1.5:

angular
    .module('myModule')
    .component('myComponent', {
        templateUrl: "my.component.html",
        controller : [
            MyComponentController
        ]
    });

ControllerAs didn't help...

HTML snippet of where the problem appears ($ctrl.*):

<div class="entity-summary clear" ng-click="$ctrl.toggleInfo()"> 
  <div class="entity-col">
    {{$ctrl.entity.id}}
  </div>
  <div class="entity-col">
    {{$ctrl.entity.host}}
  </div> 
</div>
like image 357
Amio.io Avatar asked Mar 15 '16 09:03

Amio.io


2 Answers

Unfortunately Angular 1.5 components are not yet fully supported, please follow WEB-20339 for updates

like image 90
lena Avatar answered Sep 22 '22 12:09

lena


You can avoid most of the noise by (mis)using ng-init="$ctrl=$ctrl":

<div ng-init="$ctrl=$ctrl"         
     ng-click="$ctrl.toggleInfo()"
     class="entity-summary clear" > 
  <div class="entity-col">
    {{$ctrl.entity.id}}
  </div>
  <div class="entity-col">
    {{$ctrl.entity.host}}
  </div> 
</div>
like image 28
yar1 Avatar answered Sep 18 '22 12:09

yar1