[英]Pass arguments to a custom Kendo UI Notification component
I'm working off this example here: https://www.telerik.com/kendo-angular-ui/components/notification/content/我在这里处理这个例子: https://www.telerik.com/kendo-angular-ui/components/notification/content/
In the code below, in the show()
function, I'd like to pass a data to the CustomComponent.在下面的代码中,在
show()
function 中,我想将数据传递给 CustomComponent。 Is this possible to do?这可能吗?
import { Component, Output, Input, EventEmitter } from '@angular/core';
import { NotificationService, NotificationRef } from '@progress/kendo-angular-notification';
@Component({
selector: 'custom-component',
template: `
<span>{{ message }}</span>
<button class="k-button k-outline" (click)="ignoreNotification($event)">IGNORE</button>
`
})
export class CustomComponent {
@Input() customData; // <--- DATA FROM PARENT. MY CODE
@Output() public ignore: EventEmitter<any> = new EventEmitter();
public message = 'Weather: Chance of rain today. There is a 40 percent chance of rain, mainly before 1 p.m.';
public ignoreNotification(event: Event): void {
event.preventDefault();
this.ignore.emit();
}
// I'd like to obtain the data here when I go to use it.
private myFunc() {
const getsData = this.customData;
}
}
@Component({
selector: 'my-app',
template: `
<p>Show Custom Component rendered into warning type Notification</p>
<button class="k-button" (click)="show()">Show</button>
`
})
export class AppComponent {
constructor(private notificationService: NotificationService) {}
public show(): void {
const notificationRef: NotificationRef = this.notificationService.show({
content: CustomComponent,
animation: { type: 'slide', duration: 200 },
position: { horizontal: 'right', vertical: 'top' },
type: { style: 'warning', icon: false },
closable: false
});
if (notificationRef) {
notificationRef.content.ignore
.subscribe(() => notificationRef.hide());
}
}
}
Instead of using Input, just create public property and set it using content.无需使用输入,只需创建公共属性并使用内容进行设置。
Example with message property带有消息属性的示例
Inside injected component:内部注入组件:
public message: string;
Set using content on notificationRef:使用 notificationRef 上的内容设置:
if (notificationRef) {
const notificationContent = notificationRef.content as any;
notificationContent.message = 'test';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.