Message全局提示
- 可提供成功、警告和错误等反馈信息。
- 顶部居中显示并自动消失,是一种不打断用户操作的轻量级提示方式。
想要了解更多关于单独引入组件的内容,可以在快速上手页面进行查看。
如果要修改全局默认配置,你可以设置提供商 的值来修改。(如:在你的模块的providers
中加入 { provide: NZ_MESSAGE_CONFIG, useValue: { nzDuration: 3000 }}
,NZ_MESSAGE_CONFIG
可以从 ng-zorro-antd
中导入)
默认全局配置为:
{
nzDuration: 3000,
nzMaxStack: 7,
nzPauseOnHover: true,
nzAnimate: true
}
信息提醒反馈。
import { Component } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'nz-demo-message-duration',
template: `
`
})
export class NzDemoMessageDurationComponent {
createBasicMessage(): void {
this.message.success('This is a prompt message for success, and it will disappear in 10 seconds', {
nzDuration: 10000
});
constructor(private message: NzMessageService) {}
}
可通过订阅 onClose
事件在 message 关闭时做出某些操作。以上用例将依次打开三个 message。
包括成功、失败、警告。
import { Component } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'nz-demo-message-other',
template: `
<button nz-button (click)="createMessage('success')">Success</button>
<button nz-button (click)="createMessage('error')">Error</button>
<button nz-button (click)="createMessage('warning')">Warning</button>
`,
styles: [
[nz-button] {
margin-right: 8px;
}
`
]
})
export class NzDemoMessageOtherComponent {
createMessage(type: string): void {
this.message.create(type, `This is a message of ${type}`);
}
constructor(private message: NzMessageService) {}
}
进行全局 loading,异步自行移除。
组件提供了一些服务方法,使用方式和参数如下:
NzMessageService.success(content, [options])
NzMessageService.error(content, [options])
NzMessageService.info(content, [options])
NzMessageService.warning(content, [options])
NzMessageService.loading(content, [options])
options
支持设置的参数如下:
还提供了全局销毁方法:
NzMessageService.remove(id)
// 移除特定id的消息,当id为空时,移除所有消息(该消息id通过上述方法返回值中得到)
当你调用 NzMessageService.success
或其他方法时会返回该对象。
export interface NzMessageDataFilled {
}