2017-08-05 70 views
0

我沿着這個Ionic 2教程,遇到問題。問題在於TypeScript(請參見圖片)。這裏是video tutorial I followedIonic TypeScript錯誤(Property'nav'在'HomePage'類型上不存在)

the error message

這裏是src/pages/home/home.html

<ion-header> 
 
    <ion-navbar primary *navbar> 
 
    <ion-title> 
 
     Tasker 
 
    </ion-title> 
 

 
    <ion-buttons end> 
 
     <button ion-button icon-only> 
 
     <ion-icon name="add"></ion-icon> 
 
     </button> 
 
    </ion-buttons> 
 

 
    </ion-navbar> 
 
</ion-header> 
 

 
<ion-content> 
 

 
    <ion-list> 
 

 
    <ion-item *ngIf="!task.length"> 
 
     No Task Available 
 
     <p> Click <ion-icon name="add"> to add task</ion-icon></p> 
 
    </ion-item> 
 

 
    <ion-item-sliding *ngFor="#t of tasks"> 
 
     <ion-item> 
 
     <ion-toggle></ion-toggle> 
 
     <ion-label> 
 
      <h2 [ngClass]="t.status">{{t.task}}</h2> 
 
      <p [ngClass]="t.priority">{{t.priority}}</p> 
 
     </ion-label> 
 
     </ion-item> 
 

 
     <ion-item-options> 
 

 
     <button primary><ion-icon name="clipboard"></ion-icon>Edit</button> 
 
     <button danger><ion-icon name="trash"></ion-icon>Delete</button> 
 

 
     </ion-item-options> 
 
    </ion-item-sliding> 
 

 

 
    </ion-list> 
 

 
</ion-content>

而且src/pages/home/home.ts發生錯誤!:

import { Component } from '@angular/core'; 
 
import { NavController } from 'ionic-angular'; 
 

 
@Component({ 
 
    selector: 'page-home', 
 
    templateUrl: 'home.html' 
 
}) 
 
export class HomePage { 
 

 
    static get parameters(){ 
 
    return [[NavController]] 
 
    } 
 

 

 
    constructor(nav) { 
 
    this.nav = nav; 
 

 

 
    this.tasks = [ 
 
     {task:'test1', priority:'low', status:'pending'}, 
 
     {task:'test2', priority:'high', status:'done'}, 
 
     {task:'test3', priority:'normal', status:'pending'} 
 
    ] 
 
    } 
 

 
}

回答

3

有幾個打字稿問題,我看到:

  • 你不需要static get parameters功能在所有。
  • 如果您注射NavController,你可以像這樣指定它:

    constructor(private nav:NavController) { 
        //this.nav = nav; This is not required if you have set access 
        //specifier in constructor parameter 
        // removed rest of code for brevity 
    } 
    
  • 最後,如果你需要創建一個打字原稿類變量,你需要在類中聲明。

    export class HomePage { 
        tasks:any[]=[] 
        // contstructor and other code 
    } 
    

注意參考視頻好像是用離子的更舊版本。我建議你找到最近的教程視頻。

+0

我嘗試了你的建議,並發現另一個錯誤,說它不能讀取home.html文件中的一些屬性,說它們是不確定的 –

+0

你必須調試..例如'task.length'可能應該是任務.length' –

+0

解析器錯誤:位於[#t中的任務]中的第1列中的意外標記#ng:///AppModule/[email protected]:22,我現在應該做什麼?對不起,如此有需要... –

相關問題