PhpStorm marks existing variable as "unresolved variable"

I am working with AngularJS

in PhpStorm. I am new to both. I have two files in my project, index.html

and app.js

. From index.html

I am referring to a variable store.products

defined in app.js

, but PhpStorm is telling me that it cannot resolve the variable.

PhpStorm has no problem with product.name

.

The code works without issue in the browser, so I figured there must be something wrong with the editor. Or maybe the bug is just subtle that the browser just ignores.

index.html

(problem in ng-repeat directive):

<!DOCTYPE html>
<html ng-app="gemStore">
<head lang="en">
  (...)
</head>
<body ng-controller="StoreController as store">
  <ul class="list-group">
    <li class="list-group-item" ng-repeat="product in store.products">
      <h3>
        {{product.name}}
      </h3>
    </li>
  </ul>

  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.min.js"></script>
  <script type="text/javascript" src="app.js"></script>
</body>
</html>

      

app.js

:

(function() {
  var app = angular.module('gemStore', []);

  app.controller('StoreController', function() {
    this.products = gems;
  });

  var gems = [
    ...
  ];

})();

      

I was hoping someone would spot the error. Even though the page displays correctly in the browser, it is rather annoying that PhpStorm displays an error.

Edit: In app.js

, this.products

not flagged "unused definition: products"

when I link store.products

to index.html

. So for some reason PhpStorm can see that the variable is in use, but can't see it from the point of view index.html

.

+3


source to share


2 answers


Yes, PhpStorm should find the link. I just tested it here and it worked with my PhpStorm.

<html ng-app="store">
<body ng-controller="StoreController as store"> <-- store is already app name.

      

You named the controller alias and your application with the same keyword store

. I think this is confusing PhpStorm. Try to give the controller a different alias.



If that still doesn't work, try this:

Launch PhpStorm, click "File / Invalid Cache" and select "Invalidate and Restart".

0


source


I can recreate the problem in PHPStorm 8 / WebStorm 9 EAP. The problem is that the Angular plugin does not correctly recognize the Angular 1.2 syntax 'as'. Please vote for WEB-11544



0


source







All Articles