Angular 在ngOnInit中使用@Input

Angular 在ngOnInit中使用@Input,angular,Angular,我已使用@Input将应用程序对象从父组件传递到子组件。现在我尝试在子组件的ngOnInit上使用它。该对象仅在ngOnChanges上可用,因此无法在ngOnInit上使用。尽管如此,我还是尝试了下面这样的方法,但无法成功 组件 @Input()应用程序; appModified; 列表详细信息(){ this.appService.getDetails(this.appModified); } ngOnChanges(){ console.log(this.app) this.appModi

我已使用
@Input
将应用程序
对象从父组件传递到子组件。现在我尝试在子组件的
ngOnInit
上使用它。该对象仅在
ngOnChanges
上可用,因此无法在
ngOnInit
上使用。尽管如此,我还是尝试了下面这样的方法,但无法成功

组件

@Input()应用程序;
appModified;
列表详细信息(){
this.appService.getDetails(this.appModified);
}
ngOnChanges(){
console.log(this.app)
this.appModified=this.app;
}
恩戈尼尼特(){
这是listDetails();
}
listDetails未定义

我试过了,但还是修不好

感谢您的帮助。谢谢你

@surazzarus

确保html模板与下面类似,其中
someString
content将实例绑定到子对象的
name
属性:

<hello [name]="someString"></hello>
最后一段代码:

import { Component, Input } from '@angular/core';

@Component({
  selector: 'hello',
  template: `<span>{{name}}</span>`
})
export class HelloComponent  {
  @Input() name: string;

  ngOnInit() {
    console.log(this.name);
}

  ngOnChanges() {
    console.log(this.name)
}
}
从'@angular/core'导入{Component,Input};
@组成部分({
选择器:“你好”,
模板:`{name}}`
})
导出类HelloComponent{
@Input()名称:string;
恩戈尼尼特(){
console.log(this.name);
}
ngOnChanges(){
console.log(this.name)
}
}
希望对你有帮助


检查整个样本

调用
this.listDetails()
ngAfterViewInit()
@Faisal中,我也尝试过,但没有成功ngoninit(){setTimeout(()=>{this.listDetails();},0}您知道可以多次调用ngOnChanges,对吗?如果您检查父组件中的输入数据,那么它将在数据满时填充数据,
这有什么问题?
import { Component, Input } from '@angular/core';

@Component({
  selector: 'hello',
  template: `<span>{{name}}</span>`
})
export class HelloComponent  {
  @Input() name: string;

  ngOnInit() {
    console.log(this.name);
}

  ngOnChanges() {
    console.log(this.name)
}
}