简体   繁体   English

Ionic TypeScript错误(类型“ HomePage”上不存在属性“ nav”)

[英]Ionic TypeScript Error (Property 'nav' does not exist on type 'HomePage')

I am following along this Ionic 2 tutorial and encountered problems. 我正在按照Ionic 2教程进行操作,遇到了问题。 The problems are in the TypeScript (See the Picture). 问题出在TypeScript中(参见图片)。 Here is the video tutorial I followed . 这是我关注视频教程

错误信息

Here are the src/pages/home/home.html : 这是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> 

And the src/pages/home/home.ts Where the error occurred!: 以及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'} ] } } 

There are a few typescript issues I see: 我看到一些打字稿问题:

  • You dont need static get parameters function at all. 您根本不需要static get parameters功能。
  • If you are injecting NavController , you can specify it like so: 如果要注入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 } 
  • Lastly, if you need to create a class variable in Typescript, you need to declare in the class. 最后,如果需要在Typescript中创建类变量,则需要在类中声明。

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

Note the reference video seems to be using a much older version of Ionic. 请注意,参考视频似乎正在使用旧版本的Ionic。 I suggest you find a recent tutorial video. 我建议您找到最近的教学视频。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打字稿中的错误~类型void~中不存在属性 - Error in typescript ˜Property does not exist in type void˜ Typescript 错误“类型‘HTMLElement’上不存在属性‘值’”、“‘元素’类型上不存在属性‘onclick’” - Typescript error "Property 'value' does not exist on type 'HTMLElement'", "Property 'onclick' does not exist on type 'Element'" 打字稿错误:类型“元素”上不存在属性“包含”。 - Typescript error :Property 'contains' does not exist on type 'Element'.? 打字稿错误“ HTMLElement”类型不存在属性。 任何 - Typescript error Property does not exist on type 'HTMLElement'. any Typescript:“EventTarget”类型上不存在属性“className” - Typescript :Property 'className' does not exist on type 'EventTarget' 类型“#”错误中不存在属性“#” - Property "#" does not exist on type "#" error TypeScript static 方法中的属性不存在错误 - Property does not exist error in TypeScript static method Ionic 3 HttpClient连接api时发生错误,类型“对象”上不存在属性“ json” - ionic 3 HttpClient error in connecting api, Property 'json' does not exist on type 'Object' 错误:类型“ HTMLDivElement”上不存在属性“值”? 打字稿找不到我的div? - ERROR: Property 'value' does not exist on type 'HTMLDivElement' ? Typescript can't find my div? 类型错误时不存在 Angular 属性 - Angular Property does not exist on type error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM