2017-10-16 19 views
1

に存在しません:私は、このエラー得続けるプロパティは、私はこの角度4成分を持つコンポーネント

export class MenuComponent { 

constructor(private menuService: MenuService) { } 


@Input(nodes):any; 

    getMenu(path:string): void { 
    this.menuService.getData(path).subscribe(data => { 
     // Read the result field from the JSON response. 

     let newValue = JSON.stringify(data).replace('{"Node":', '['); 
     newValue = newValue.substring(0,newValue.length - 1); 
     newValue+="]"; 
     const menu=JSON.parse(newValue); 
     this.nodes = menu; 
     }); 

} 
} 

Property 'nodes' does not exist on type 'MenuComponent'をしてnodes財産が権利があるので、なぜ私は見当がつかない。

+0

'@Input()nodes:any;'? – jonrsharpe

+0

何が問題なのですか? – eli

+0

あなたの実際のコメントと私のコメントをよく比較してください! – jonrsharpe

答えて

0

私は通常、このように@入力変数を定義します。

@Input() nodes: any; 

私は2つの問題、あなたのコンポーネントがundefinedを取得するか、値を取得していないビューから

  1. を見ることができます。親コンポーネントが適切な値を送信していることを確認してください。nodesの値が正しいことを確認してください。

また

@Input() hero: Hero; 
@Input('master') masterName: string; 

で、ngInitライフサイクルフックを追加し、2通りの方法で入力を提供することができます

ngOnInit() { 
    this.nodes = this.nodes || ''; 
    } 
1

任意のものを受信しなかった場合のデフォルト値を設定することができますパブリックプロパティ名(bindingPropertyName)を提供していますが、コンポーネントクラスで使用できるプロパティはありません。

@Input(nodes):any; 

続きを読む@Inputhereを参照してください。

これが役立ちますように!

関連する問題