Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 子组件上的触发器更改检测_Angular_Jasmine - Fatal编程技术网

Angular 子组件上的触发器更改检测

Angular 子组件上的触发器更改检测,angular,jasmine,Angular,Jasmine,假设我正在测试MyComponentwho的模板包含SubComponent MyComponent看起来像这样 @Component({ selector: 'my-component', template: ` <sub-component [input]="property"></sub-component> ` }) export class MyComponent implements OnInit { property: string

假设我正在测试
MyComponent
who的模板包含
SubComponent

MyComponent看起来像这样

@Component({
  selector: 'my-component',
  template: `
    <sub-component [input]="property"></sub-component>
  `
})

export class MyComponent implements OnInit {
  property: string;
  constructor() { }

  ngOnInit() { 
    this.property = 'value passed to sub component';
  }
}
@组件({
选择器:“我的组件”,
模板:`
`
})
导出类MyComponent实现OnInit{
属性:字符串;
构造函数(){}
ngOnInit(){
this.property='传递给子组件的值';
}
}
当我测试
MyComponent
并执行
comp.ngOnInit()
时,
子组件
不会检测到
输入的更新值


如何让
子组件
检测到该更改?

您可以在您的子组件中使用生命周期挂钩。

这是否有效?我没有看到
@Input
注释,即使有注释,您也在您的孩子中使用了错误的属性名称(
property
)。