如何从对话服务向组件发送值
How to send values to a component from dialog service
我正在尝试创建自定义对话服务。
为此,我创建了一个对话服务:
import {DialogService,DialogRef,DialogCloseResult } from '@progress/kendo-angular-dialog';
import {Injectable} from "@angular/core";
import {CustomComponent} from './custom.component';
@Injectable()
export class DialogoService {
constructor(private dialogService: DialogService) { }
public confirm(title: string, content?: string): DialogRef {
return this.dialogService.open({
title: title,
content: CustomComponent ,//This is my component that holds the template
actions: [
{text: 'Yes', primary: true},
{text: 'No'}
]
});
} }
这是我的 CustomComponent
import {Component} from '@angular/core';
@Component({
moduleId : module.id,
selector: 'customcomponent',
templateUrl: './custom.component.html'
})
export class CustomComponent {
content : string ;
}
最后是我的 custom.component.html:
<div> Content: {{content}} </div>
我应该如何将内容参数从服务发送到 dialogService.open 函数?
dialogService.open 的内容参数可以是字符串、组件或模板引用。
在我的例子中,我将 CustomComponent 作为参数发送,但无法从我的服务中为此组件设置标题参数。
抱歉我的英语不好。
提前致谢。
更新:0.16版本的对话框增加了一个DialogRef.content
字段,可以用来向子组件传递信息
const dialogRef = dialogService.open({ content: MyComponent });
dialogRef.content.instance.foo = "bar";
See the documentation 一个可运行的例子。
在撰写本文时,将信息传递给子组件的唯一方法是使用将注入到组件中的服务。
即将推出的对话框版本会将 ComponentRef 传递给子组件,这将允许您在 DialogService.open
调用之后传递数据。
我正在尝试创建自定义对话服务。 为此,我创建了一个对话服务:
import {DialogService,DialogRef,DialogCloseResult } from '@progress/kendo-angular-dialog';
import {Injectable} from "@angular/core";
import {CustomComponent} from './custom.component';
@Injectable()
export class DialogoService {
constructor(private dialogService: DialogService) { }
public confirm(title: string, content?: string): DialogRef {
return this.dialogService.open({
title: title,
content: CustomComponent ,//This is my component that holds the template
actions: [
{text: 'Yes', primary: true},
{text: 'No'}
]
});
} }
这是我的 CustomComponent
import {Component} from '@angular/core';
@Component({
moduleId : module.id,
selector: 'customcomponent',
templateUrl: './custom.component.html'
})
export class CustomComponent {
content : string ;
}
最后是我的 custom.component.html:
<div> Content: {{content}} </div>
我应该如何将内容参数从服务发送到 dialogService.open 函数?
dialogService.open 的内容参数可以是字符串、组件或模板引用。 在我的例子中,我将 CustomComponent 作为参数发送,但无法从我的服务中为此组件设置标题参数。
抱歉我的英语不好。 提前致谢。
更新:0.16版本的对话框增加了一个DialogRef.content
字段,可以用来向子组件传递信息
const dialogRef = dialogService.open({ content: MyComponent });
dialogRef.content.instance.foo = "bar";
See the documentation 一个可运行的例子。
在撰写本文时,将信息传递给子组件的唯一方法是使用将注入到组件中的服务。
即将推出的对话框版本会将 ComponentRef 传递给子组件,这将允许您在 DialogService.open
调用之后传递数据。