Is there any way I can pass dynamic data to a component in Angular?

前端 未结 4 1885
抹茶落季
抹茶落季 2021-01-12 20:42

I am trying to pass data that is dynamic to a child component. But I always get the data as undefined in the child component. Below is what I am doing.

ParentComp

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 21:07

    if you are sure that your service gets data successfully so this will work :

    in the html of your parent component add the quotes :

    
    

    in your child component , you will check changes of your Inputusing the OnCh:

    ngOnChanges(changes: SimpleChanges) {   
       for (let propName in changes) {
          // when your @Input value is changed  
          if(propName === "dataNeeded"){
              console.log(dataNeeded);
          }
       }
    }
    

    Hope this would help :)

提交回复
热议问题