我正在尝试将警报从子组件传递到父组件。
我有以下app组件:
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
App.component.html:
<header>
Some header
</header>
<clr-alert [clrAlertType]="'alert-warning'" [clrAlertAppLevel]="true">
<div class="alert-item">
<span class="alert-text">
{{My_Alert_value_that_I want to pass from child}}
</span>
<div class="alert-actions">
<button class="btn alert-action">Fix</button>
</div>
</div>
</clr-alert>
<router-outlet></router-outlet>
我的孩子组成部分:
@Component({
styleUrls: ['./child.component.scss'],
templateUrl: './child.component.html',
})
export class ChildComponent {
alerts: string
constructor(){
this.alerts = "";
}
this.alert = "My alerts, which I want to show on the app.component.html"
}
有人可以帮我吗?
答案 0 :(得分:0)
您可以使用EventEmitter
将数据从子项公开给父项,并在父组件中处理事件。
官方文档有一个很好的使用EventEmitter
的例子:
https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html