3

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 referencing a variable store.products defined in app.js, but PhpStorm tells me that it cannot resolve the variable.

PhpStorm has no problems with product.name.

The code works without problems in the browser, so I figured something must be wrong with the editor. Or maybe the error is just a subtle one that the browser simply ignores.

index.html (the problem is in the 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 could spot the error. Even though the page renders correctly in the browser, it is pretty annoying that PhpStorm displays the error.

Edit: In app.js, this.products is not marked with "unused definition: products" when I reference store.products from index.html. So somehow PhpStorm can see that the variable is being used, but still can't see it from index.html's point of view.

1
  • +1 for AngularJS with PhpStorm. Commented Sep 25, 2014 at 21:23

2 Answers 2

0

Yes, PhpStorm should be able to find the reference. I just tested it here and works with my PhpStorm.

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

You've named the controller alias and your app the same keyword store. I think this is confusing PhpStorm. Try giving the controller a different alias.

If that still doesn't work, then try this:

Start PhpStorm, click menu "File / Invalidate Cache" and select "Invalidate and Restart".

Sign up to request clarification or add additional context in comments.

8 Comments

I tried renaming my app (since that's obviously a bad choice of name -- thanks) and then invalidating the cache. However, the problem remains the same. I also tried creating a new project with no luck.
@MathiasBrandt what build of PhpStorm are you using?
I am using PhpStorm 8.0.1 build #PS-138.2001.
@MathiasBrandt and you have plugin AngularJS ver 138.1988?
Yes, I just installed everything today :) I have tried continuing with the tutorial I am following. Defining a new controller poses even more problems. PhpStorm does not see the entire new controller. I suspect something fundamental is wrong in my app.js ...
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.