Why do I need to call detectChanges() with the default change detection strategy?

前端 未结 2 1940

I am working on an Angular 4 app, but I am having a problem inasmuch as I am having to call this.changeDetectorRef.detectChanges(); to update the view when the

2条回答
  •  死守一世寂寞
    2021-01-01 17:58

    You can Input your searchResults into the child Components

    @Input() searchResults;
    

    after that you pass it trough the parent template

    // parent template
    
    

    you can use it in the child template

    // child template 
    
    

    after that you can 'listen' for changes in this property in the child Component

    export class ChildComponent implements OnChanges {
    
      @Input() searchResults;
    
      constructor() { }
    
      ngOnChanges() {
        // some code
      }
    

    Every time searchResults is changed the changes will be populated in the child component, the values in the child template will get the new value.

提交回复
热议问题