File

src/app/materials/notification/notification.component.ts

Implements

OnInit

Metadata

selector app-notification
styleUrls ./notification.component.scss
templateUrl ./notification.component.html

Index

Properties
Methods

Constructor

constructor(_notification: NotificationService)
Parameters :
Name Type Optional
_notification NotificationService No

Methods

clear
clear()
Returns : void
ngOnInit
ngOnInit()
Returns : void
show
show()
Returns : void
success
success()
Returns : void
warn
warn()
Returns : void

Properties

duration
Type : number
Default value : 3000
message
Type : string
Default value : '测试消息'
position
Type : any
title
Type : string
Default value : '测试标题'
type
Type : string
import { Component, OnInit } from '@angular/core';
import { NotificationService } from '../../component';

@Component({
  selector: 'app-notification',
  templateUrl: './notification.component.html',
  styleUrls: ['./notification.component.scss']
})
export class NotificationComponent implements OnInit {

  title: string = '测试标题';
  message: string = '测试消息';
  duration: number = 3000;
  position: any;
  type: string;

  constructor(private _notification: NotificationService) {
  }

  ngOnInit() {
  }


  show() {
    console.log(this.position);
    this._notification.open(this.message, this.title, {
      duration: this.duration
    }, this.type);
  }

  success() {
    this._notification.success('测试消息', '测试标题');
  }

  warn() {
    this._notification.warn('测试消息', '测试标题');
  }

  clear() {
    this._notification.dismiss();
  }

}
<mat-card>
  <mat-card-title>Notification 通知</mat-card-title>
  <mat-card-content>

    <mat-form-field>
      <input matInput placeholder="Title" [(ngModel)]="title">
    </mat-form-field>

    <mat-form-field>
      <input matInput placeholder="Message" [(ngModel)]="message">
    </mat-form-field>

    <mat-form-field>
      <input matInput placeholder="Duration" [(ngModel)]="duration">
    </mat-form-field>

    <div class="m-20">
      <mat-radio-group [(ngModel)]="position">
        <mat-radio-button value="1">top right</mat-radio-button>
      </mat-radio-group>
    </div>

    <div class="m-20">
      <mat-radio-group [(ngModel)]="type">
        <mat-radio-button value="info">info</mat-radio-button>
        <mat-radio-button value="success">success</mat-radio-button>
        <mat-radio-button value="warn">warn</mat-radio-button>
      </mat-radio-group>
    </div>

  </mat-card-content>
  <mat-card-actions align="center">
    <button mat-raised-button color="primary" (click)="show()">显示</button>
    <button mat-raised-button (click)="clear()">清除</button>
  </mat-card-actions>
</mat-card>

./notification.component.scss

:host {
  display: block;
}

mat-card {
  margin: 20px;
}

mat-form-field {
  display: block;
}

mat-radio-group {
  display: block;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""