[英]Ionic TypeScript Error (Property 'nav' does not exist on type 'HomePage')
我正在按照Ionic 2教程进行操作,遇到了问题。 问题出在TypeScript中(参见图片)。 这是我关注的视频教程 。
这是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'} ] } }
我看到一些打字稿问题:
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 }
最后,如果需要在Typescript中创建类变量,则需要在类中声明。
export class HomePage { tasks:any[]=[] // contstructor and other code }
请注意,参考视频似乎正在使用旧版本的Ionic。 我建议您找到最近的教学视频。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.