File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed
components-examples/material/button-toggle Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ < mat-button-toggle-group [formControl] ="fontStyle " aria-label ="Font Style ">
2
+ < mat-button-toggle value ="bold "> Bold</ mat-button-toggle >
3
+ < mat-button-toggle value ="italic "> Italic</ mat-button-toggle >
4
+ < mat-button-toggle value ="underline "> Underline</ mat-button-toggle >
5
+ </ mat-button-toggle-group >
6
+ < p > Chosen value is {{fontStyle.value}}</ p >
Original file line number Diff line number Diff line change
1
+ import { Component } from '@angular/core' ;
2
+ import { FormControl } from '@angular/forms' ;
3
+
4
+ /**
5
+ * @title Button-toggles with forms
6
+ */
7
+ @Component ( {
8
+ selector : 'button-toggle-forms-example' ,
9
+ templateUrl : 'button-toggle-forms-example.html' ,
10
+ } )
11
+ export class ButtonToggleFormsExample {
12
+ fontStyle = new FormControl ( ) ;
13
+ }
Original file line number Diff line number Diff line change 1
1
import { NgModule } from '@angular/core' ;
2
+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
2
3
import { MatButtonToggleModule } from '@angular/material/button-toggle' ;
3
4
import { MatIconModule } from '@angular/material/icon' ;
4
5
import {
@@ -9,25 +10,30 @@ import {
9
10
} from './button-toggle-exclusive/button-toggle-exclusive-example' ;
10
11
import { ButtonToggleOverviewExample } from './button-toggle-overview/button-toggle-overview-example' ;
11
12
import { ButtonToggleHarnessExample } from './button-toggle-harness/button-toggle-harness-example' ;
13
+ import { ButtonToggleFormsExample } from './button-toggle-forms/button-toggle-forms-example' ;
12
14
13
15
export {
14
16
ButtonToggleAppearanceExample ,
15
17
ButtonToggleExclusiveExample ,
16
18
ButtonToggleOverviewExample ,
17
19
ButtonToggleHarnessExample ,
20
+ ButtonToggleFormsExample ,
18
21
} ;
19
22
20
23
const EXAMPLES = [
21
24
ButtonToggleAppearanceExample ,
22
25
ButtonToggleExclusiveExample ,
23
26
ButtonToggleOverviewExample ,
24
27
ButtonToggleHarnessExample ,
28
+ ButtonToggleFormsExample ,
25
29
] ;
26
30
27
31
@NgModule ( {
28
32
imports : [
33
+ FormsModule ,
29
34
MatButtonToggleModule ,
30
35
MatIconModule ,
36
+ ReactiveFormsModule ,
31
37
] ,
32
38
declarations : EXAMPLES ,
33
39
exports : EXAMPLES ,
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ be configured globally using the `MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS` injection t
22
22
23
23
<!-- example(button-toggle-appearance) -->
24
24
25
+ ### Use with ` @angular/forms `
26
+ ` <mat-button-toggle-group> ` is compatible with ` @angular/forms ` and supports both ` FormsModule `
27
+ and ` ReactiveFormsModule ` .
28
+
25
29
### Accessibility
26
30
The button-toggles internally use native ` button ` elements with ` aria-pressed ` to convey
27
31
their toggled state. The button-toggle-group surrounding the individual buttons applies
You can’t perform that action at this time.
0 commit comments