我正在使用AngularJS
在PhpStorm中。我對這兩個都是新手。
我在我的項目中有兩個文件,index.html
和app.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.js
,this.products
並不當我參考store.products
從index.html
標有"unused definition: products"
。所以不知怎的,PhpStorm可以看到這個變量正在被使用,但仍然無法從index.html
的角度看到它。
+1對於AngularJS與PhpStorm。 – cgTag 2014-09-25 21:23:43