我正在使用Angular 2,想知道是否能够在toast消息中添加超链接。我在网上搜索了一些可能有用的内容,但我想知道是否有一种清晰明确且易于实现的方法。谢谢!
编辑:或者是否有一种通过单击toast消息导航到不同URL的方法。
编辑:或者是否有一种通过单击toast消息导航到不同URL的方法。
在嵌入任何类型的HTML内容到toast中时,有两种不同的方法。
通过从angular2-toaster
导入BodyOutputType,您可以指定TrustedHtml或Component。第一种方法允许您直接将html传递到toast的body
参数中:
import { BodyOutputType } from 'angular2-toaster';
popTrustedHtmlToast() {
var toast: Toast = {
type: 'info',
title: 'Here is a Toast Title',
body: '<a target="_blank" href="https://www.google.com">Here is a Toast Body<a/>',
bodyOutputType: BodyOutputType.TrustedHtml,
showCloseButton: true
};
this.toasterService.pop(toast);
}
@Component({
selector: 'custom-component',
template: `<a target="_blank" href="https://www.google.com">Here is a Toast Body</a>`
})
export class CustomComponent { }
@NgModule({
bootstrap: [CustomComponent],
declarations: [CustomComponent]
})
export class CustomComponentModule { }
popComponentToast() {
var toast: Toast = {
type: 'info',
title: 'Here is a Toast Title',
body: CustomComponent,
bodyOutputType: BodyOutputType.Component,
showCloseButton: true
};
this.toasterService.pop(toast);
}