2014-09-25 68 views
3

我正在使用AngularJS在PhpStorm中。我對這兩個都是新手。
我在我的項目中有兩個文件,index.htmlapp.js。從index.html,我引用app.js中定義的變量store.products,但PhpStorm告訴我它無法解析變量。PhpStorm將現有變量標記爲「未解決變量」

PhpStorm與product.name沒有問題。

該代碼在瀏覽器中沒有問題,因此我認爲編輯器一定是錯誤的。或者,也許錯誤只是瀏覽器忽略的一個微妙之處。

index.html(問題是在NG-重複指令):

<!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 = [ 
    ... 
    ]; 

})(); 

我希望有人能找到這個錯誤。即使頁面在瀏覽器中正確渲染,PhpStorm顯示錯誤也很煩人。

編輯:app.jsthis.products並不當我參考store.productsindex.html標有"unused definition: products"。所以不知怎的,PhpStorm可以看到這個變量正在被使用,但仍然無法從index.html的角度看到它。

+0

+1對於AngularJS與PhpStorm。 – cgTag 2014-09-25 21:23:43

回答

0

是的,PhpStorm應該能夠找到參考。我只是在這裏測試它,並與我的PhpStorm一起工作。

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

您已經命名控制器別名,你的應用程序相同的關鍵字store。我認爲這是令人困惑的PhpStorm。嘗試給控制器一個不同的別名。

如果仍然不起作用,那就試試這個:

開始PhpStorm,單擊菜單「文件/無效高速緩存」,選擇「無效,並重新啓動」。

+0

我嘗試重命名我的應用程序(因爲這顯然是名稱的錯誤選擇 - 謝謝),然後使緩存無效。但是,問題依然如此。我也嘗試創建一個沒有運氣的新項目。 – 2014-09-25 21:45:34

+0

@MathiasBrandt你正在使用什麼樣的PhpStorm? – cgTag 2014-09-25 21:51:16

+0

我使用PhpStorm 8.0.1 build#PS-138.2001。 – 2014-09-25 21:52:37

0

我可以在PHPStorm 8/WebStorm 9 EAP中重新創建問題。問題是Angular插件沒有正確識別Angular 1.2'作爲語法。請投票支持WEB-11544