javascript - 将参数传递给自定义 Kendo UI 通知组件

标签 javascript angular kendo-ui toast

我正在这里处理这个例子: https://www.telerik.com/kendo-angular-ui/components/notification/content/

在下面的代码中,在 show() 函数中,我想将数据传递给 CustomComponent。这可以做到吗?

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());
        }
    }
}

最佳答案

不使用输入,只需创建公共(public)属性并使用内容设置它。

消息属性示例

注入(inject)组件内部:

 public message: string;

设置使用 notificationRef 上的内容:

 if (notificationRef) {
  const notificationContent = notificationRef.content as any;
  notificationContent.message = 'test';
}

关于javascript - 将参数传递给自定义 Kendo UI 通知组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58964162/

相关文章:

asp.net-mvc - Kendo UI DropDownListFor html 包装器 - 如何将 BindTo 设置到模型中的集合?而不是 ViewData 或 Viewbag

javascript - Kendo UI 网格始终从第 0 页开始

javascript - 两个不同的计算和绘图循环

javascript - 在 Windows 平台上启用 Electron 应用程序通知的粘性行为

typescript - 订阅 Angular 2 中组件属性的更改以进行去抖自动保存?

angular - *ng 直到点击才更新

javascript - Sequelize - 在关联的其他地方使用时防止破坏行

javascript - 如何将 jQuery 的 insertBefore() 函数与 HTML 的 javascript 字符串一起使用?

javascript - 无法从范围数组 AngularJS 中删除元素

jquery - 按需绑定(bind) KendoUI 下拉列表