[英]Webstorm reports error with code that runs
我正在做一個關於Angular的教程,並且以下行出現“期望換行或分號”錯誤:
<tr *ngFor='#product of products'>
代碼運行良好,如何使Webstorm忽略該錯誤? 這是有錯誤的模板的全文:
<div class="panel panel-primary">
<div class="page-header">{{pageTitle}}</div>
<div class="panel-body">
<div class="row">
<div class="col-md-2">Filter By:</div>
<div class="col-md-4"><input type="text"/> </div>
</div>
<div class="row">
<div class="col-md-6"><h3>Filtered by:</h3></div>
</div>
</div>
<div class="table-responsive">
<table class="table" *ngIf="products && products.length">
<thead>
<tr>
<th><button class="btn btn-primary">Show Image</button> </th>
<th>Product</th>
<th>Code</th>
<th>Available</th>
<th>Price</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<tr *ngFor='#product of products'>
<td></td>
<td>{{product.productName}}</td>
<td>{{product.productCode}}</td>
<td>{{product.releaseDate}}</td>
<td>{{product.price}}</td>
<td>{{product.starRating}}</td>
</tr>
</tbody>
</table>
</div>
</div>
我有同樣的錯誤,重啟並沒有幫助。 原來,這是一種舊語法。 從Angular 2 beta.17開始,語法從
<tr *ngFor='#product of products'>
至
<tr *ngFor='let product of products'>
在我的情況下,PHPStorm 2016.3.2可以識別這種新語法,但是我的舊語法代碼正在編譯,因為它已設置為使用Angular 2 beta.13。
為了在項目中修復它,我更改了上面的語法,然后在package.json中更改了
"dependencies": {
"angular2": "2.0.0-beta.13",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.6"
},
至
"dependencies": {
"angular2": "2.0.0-beta.17",
"rxjs": "5.0.0-beta.6",
"zone.js": "0.6.12"
},
並運行npm update
。 對我來說,一切順利。
有關更多詳細信息,請參見https://johnpapa.net/angular-2-ngfor/ 。
只需重新啟動webstorm,錯誤就消失了。 在解決相同解決方案時,我還遇到了其他一些類似的錯誤。 會為花掉這50塊錢而暫時使用崇高而感到難過。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.