1
1
import { Component } from '@angular/core' ;
2
- import { MdChipInputEvent } from '@angular/material' ;
2
+ import { MdChipInputEvent , MdSnackBar } from '@angular/material' ;
3
3
4
4
5
5
export interface Person {
@@ -29,6 +29,15 @@ export class ChipsAccessibilityDemo {
29
29
{ name : 'Paul' }
30
30
] ;
31
31
32
+ availableColors = [
33
+ { name : 'none' , color : '' } ,
34
+ { name : 'Primary' , color : 'primary' } ,
35
+ { name : 'Accent' , color : 'accent' } ,
36
+ { name : 'Warn' , color : 'warn' }
37
+ ] ;
38
+
39
+ constructor ( public snackBar : MdSnackBar ) { }
40
+
32
41
displayMessage ( message : string ) : void {
33
42
this . message = message ;
34
43
}
@@ -39,20 +48,24 @@ export class ChipsAccessibilityDemo {
39
48
40
49
// Add our person
41
50
if ( ( value || '' ) . trim ( ) ) {
42
- this . people . push ( { name : value . trim ( ) } ) ;
51
+ const name = value . trim ( ) ;
52
+ this . people . push ( { name : name } ) ;
53
+ this . snackBar . open ( `${ name } added` , '' , { duration : 2000 } ) ;
43
54
}
44
55
45
56
// Reset the input value
46
57
if ( input ) {
47
58
input . value = '' ;
48
59
}
60
+
49
61
}
50
62
51
63
remove ( person : Person ) : void {
52
64
let index = this . people . indexOf ( person ) ;
53
65
54
66
if ( index >= 0 ) {
55
67
this . people . splice ( index , 1 ) ;
68
+ this . snackBar . open ( `${ person . name } deleted` , '' , { duration : 2000 } ) ;
56
69
}
57
70
}
58
71
@@ -61,10 +74,4 @@ export class ChipsAccessibilityDemo {
61
74
}
62
75
63
76
64
- availableColors = [
65
- { name : 'none' , color : '' } ,
66
- { name : 'Primary' , color : 'primary' } ,
67
- { name : 'Accent' , color : 'accent' } ,
68
- { name : 'Warn' , color : 'warn' }
69
- ] ;
70
77
}
0 commit comments