Passing data from Parent to Child via template

让人想犯罪 __ 提交于 2019-12-06 07:39:52

It should be,

<app-list [user]="username"></app-list>

Alternatively you can use @ViewChild() decorator to achieve the below

export class UserComponent implements OnInit {
 @ViewChild(AppListCopmonent) appList: AppListComponent;

  ngOnInit() {   
      this.appList.user = this.username
 }  
}

Update based on chat : Before assigning the value check if the data is there as

this.apiService.getUser(params['username']).subscribe((response: Response) => {      
  if(response){
      console.log(response.json());
      this.username = response.json().username;
      this.reputation = response.json().reputation;
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!