一、父组件
1.在父组件module文件导入
import { NgModule } from '@angular/core';
import {SimpleNotificationsModule} from 'angular2-notifications';
@NgModule({
imports: [
SimpleNotificationsModule.forRoot(),
],
})
export class AppModule { }
2.html 使用组件
<simple-notifications [options]="config" class="simple-notifications simple-notification-wrapper"></simple-notifications>
二、子组件
1.导入 ts文件
import { NotificationsService } from 'angular2-notifications';
2.注入服务
constructor(private notify: NotificationsService) {
}
3.使用
noDev() {
this.notify.info('待开发');
}
4.NotificationsService全部方法
export declare class NotificationsService {
globalOptions: any;
constructor(globalOptions: any);
emitter: Subject<NotificationEvent>;
icons: Icons;
set(notification: Notification, to: boolean): Notification;
success(title?: any, content?: any, override?: any): Notification;
error(title?: any, content?: any, override?: any): Notification;
alert(title?: any, content?: any, override?: any): Notification;
info(title?: any, content?: any, override?: any): Notification;
warn(title?: any, content?: any, override?: any): Notification;
bare(title?: any, content?: any, override?: any): Notification;
create(title?: any, content?: any, type?: NotificationType, override?: any): Notification;
html(html: any, type?: NotificationType, override?: any, icon?: string): Notification;
remove(id?: string): void;
}