【发布时间】:2019-07-25 22:33:58
【问题描述】:
我想要一个组件将输入发送到另一个组件。下面是代码 .ts 和 .html。的两个组件。 现在的问题是父组件的html页面也显示了子组件的html部分……我希望组件只传递一个字符串给子组件
父母.ts
import ...
@Component({
selector: 'app-parent',
templateUrl: './parent.html',
styleUrls: ['./parent.css']
})
export class ParentComponent implements OnInit {
sostegno : string;
constructor() { }
ngOnInit() { }
avvia1() {
this.sostegno = "xxx";
this.router.navigate(['./xxx'], { relativeTo: this.route });
}
avvia2()
this.sostegno = "yyy";
this.router.navigate(['./yyy'], { relativeTo: this.route });
}
}
父.html
<div>
...
</div>
<app-child [sostegno]="sostegno"></app-child>
Child.ts
import ...
@Component({
selector: 'app-child',
templateUrl: './child.html',
styleUrls: ['./child.css']
})
export class ChildComponent implements OnInit {
@Input() sostegno : string;
constructor() { }
ngOnInit() {
console.log(this.sostegno);
}
}
【问题讨论】:
标签: html angular input components interaction