File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
components-examples/material/button-toggle Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ < section >
2+ < h4 > Button Toggle inside of a Template-driven form</ h4 >
3+ < mat-button-toggle-group [(ngModel)] ="fontStyle " aria-label ="Font Style ">
4+ < mat-button-toggle value ="bold "> Bold</ mat-button-toggle >
5+ < mat-button-toggle value ="italic "> Italic</ mat-button-toggle >
6+ < mat-button-toggle value ="underline "> Underline</ mat-button-toggle >
7+ </ mat-button-toggle-group >
8+ < p > Chosen value is {{fontStyle}}</ p >
9+ </ section >
10+
11+ < section >
12+ < h4 > Button Toggle inside of a Reactive form</ h4 >
13+ < mat-button-toggle-group [formControl] ="fontStyleControl " aria-label ="Font Style ">
14+ < mat-button-toggle value ="bold "> Bold</ mat-button-toggle >
15+ < mat-button-toggle value ="italic "> Italic</ mat-button-toggle >
16+ < mat-button-toggle value ="underline "> Underline</ mat-button-toggle >
17+ </ mat-button-toggle-group >
18+ < p > Chosen value is {{fontStyleControl.value}}</ p >
19+ </ section >
20+
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+ fontStyleControl = new FormControl ( ) ;
13+ fontStyle ?: string ;
14+ }
Original file line number Diff line number Diff line change 11import { NgModule } from '@angular/core' ;
2+ import { FormsModule , ReactiveFormsModule } from '@angular/forms' ;
23import { MatButtonToggleModule } from '@angular/material/button-toggle' ;
34import { MatIconModule } from '@angular/material/icon' ;
45import {
@@ -9,25 +10,30 @@ import {
910} from './button-toggle-exclusive/button-toggle-exclusive-example' ;
1011import { ButtonToggleOverviewExample } from './button-toggle-overview/button-toggle-overview-example' ;
1112import { ButtonToggleHarnessExample } from './button-toggle-harness/button-toggle-harness-example' ;
13+ import { ButtonToggleFormsExample } from './button-toggle-forms/button-toggle-forms-example' ;
1214
1315export {
1416 ButtonToggleAppearanceExample ,
1517 ButtonToggleExclusiveExample ,
1618 ButtonToggleOverviewExample ,
1719 ButtonToggleHarnessExample ,
20+ ButtonToggleFormsExample ,
1821} ;
1922
2023const EXAMPLES = [
2124 ButtonToggleAppearanceExample ,
2225 ButtonToggleExclusiveExample ,
2326 ButtonToggleOverviewExample ,
2427 ButtonToggleHarnessExample ,
28+ ButtonToggleFormsExample ,
2529] ;
2630
2731@NgModule ( {
2832 imports : [
33+ FormsModule ,
2934 MatButtonToggleModule ,
3035 MatIconModule ,
36+ ReactiveFormsModule ,
3137 ] ,
3238 declarations : EXAMPLES ,
3339 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
2222
2323<!-- example(button-toggle-appearance) -->
2424
25+ ### Use with ` @angular/forms `
26+ ` <mat-button-toggle-group> ` is compatible with ` @angular/forms ` and supports both ` FormsModule `
27+ and ` ReactiveFormsModule ` .
28+
2529### Accessibility
2630The button-toggles internally use native ` button ` elements with ` aria-pressed ` to convey
2731their toggled state. The button-toggle-group surrounding the individual buttons applies
You can’t perform that action at this time.
0 commit comments