2017-05-11 3 views
0

プロパティXがタイプY上に存在しない、私はそのエラー取得してい

Property 'module' does not exist on type 'Menu'.

Property 'parentId' does not exist on type 'Menu'.

とコードは次のようになります。

private menus: Menu[]; 


for (var i = 0; i < this.menus.length; i++) { 
      if ((this.currRoute == "/" + this.ls.actLan + this.menus[i].module) && this.menus[i].parentId !== 0) { 
       this.IsActive.emit(this.menus[i].parentId); 
      } else { 
       this.IsActive.emit(0); 
      } 
     } 

しかし私はTSファイルことをインポートしている

import { Menu } from './menu'; 

ここにはこれらのプロパティがあります

export class Menu { 
    constructor(
     id: number, 
     type: number, 
     module: any, 
     urlType: string, 
     url: string, 
     name: string, 
     parentId: any 
    ) { } 
} 

何が間違っている可能性がありますか?このような

+1

なしが宣言されていないのいずれか' private'それは基本的に を何もしません。宣言するか代入するかは、今は 'Object'には全くプロパティがありません。 –

+0

@NeilLunnありがとう – gsiradze

答えて

2

は、あなたが実際にMenuクラス上の任意の特性を有していません。コンストラクタ引数からプロパティを自動的に作成することができます。 parameter propertiesを参照してください:

export class Menu { 
    constructor(
     public id: number, 
     public type: number, 
     public module: any, 
     public urlType: string, 
     public url: string, 
     public name: string, 
     public parentId: any 
    ) { } 
} 

これで、すべてのパラメータもMenuのパブリックプロパティになります。


それとも、パラメータプロパティを使用したくない場合は、次のように一つずつを定義することができます: `constructor`の引数の

export class Menu { 
    id: number; 
    // ... 
    constructor(id: number, type: number, module: any, url: string, name: string, parentId: any) { 
     this.id = id; 
     // ... 
    } 
} 
0

変更して、

export class Menu { 

    id: number; 
    type: number; 
    module: any; 
    urlType: string; 
    url: string; 
    name: string; 
    parentId: any; 
    constructor(id: number, type: number, module: any, url: string, name: string, parentId: any) { 
     this.id = id; 
     this.module = module; 
     this.type = type; 
     this.url = url; 
     this.name = name; 
     this.parentId = parentId; 
    } 
} 
関連する問題