私は2つのファイルを持っています。 app.tsとChild.ts親の角度2でトリガーされた子コンポーネントの変数の変化を検出
私はappからchildに変数を送信しています。私は変数の変化を検出し、それに応じてデータを表示したいと思います。私は変数の変化を検出することができません。
ヘルプ私はPlunkerリンクを添付しており、また、私はファイル
App.tsが
//our root app component
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {ChildCom} from './child.ts'
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello</h2>
<child-com newdata={{data}}></child-com>
</div>
`,
})
export class App {
data: any = [];
constructor(){
this.data = [{"name":"control","status":"false"}];
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App, ChildCom ],
bootstrap: [ App ]
})
export class AppModule {}
Child.tsファイルコメントでChild.tsファイルで何をしたいかを説明しました
import {Component, Input} from '@angular/core';
@Component({
selector: 'child-com',
template: `
<div>
<p>Controls: {{newdata}}</p>
</div>
`,
})
export class ChildCom {
@Input() newdata: any = [];
constructor(){
}
// here I want to check if value of control in newdata variable is false
// then display message on front end "your controls are not working"
// if value of control in newdata variable is true
// then display message on front end "your controls are working fine."
// this should automatically happen whenever I change the value of newdata variable
}
ありがとうございました。 ngOnChangesは私のために働いた。ヒントのためにありがとう。 – amansoni211