我有两个组成部分的仪表板&技能,我想传递类型的仪表板,以用于技能。但错误还没有定义。
仪表板组件:
export class DashboardComponent implements OnInit {
type: string;
constructor() { }
ngOnInit() {
this.type = "Agent";
}技能部分是:
export class SkillComponent implements OnInit{
@Input() type: string;
constructor() { }
ngOnInit() {
console.log(this.type);
}仪表板组件模板:
<div class="container">
<div class="row">
<app-skill-list type="type"></app-skill-list>
</div>
</div>发布于 2018-01-28 12:14:07
您需要使用注释类型的
<app-skill-list [type]="type"></app-skill-list>发布于 2018-01-28 13:38:14
您可以通过queryParams将组件的一个变量的值传递给其他组件。
使用queryParams指令和routerLink传递queryParams。
Dashboard.html<a [routerLink] = "['/skill']" [queryParams] ="{type :[type] }">
Skill.ts
data :any;
type : any;
Export class Skill implements OnInit {
constructor(private route: ActivatedRoute)
ngOnInit (){
this.data = this.route
. queryParams
. subscribe (params =>{
this.type = params['type']
})
//Now you can console it in skill component
}
}https://stackoverflow.com/questions/48486222
复制相似问题