在MatButtonToggleGroup指令上设置默认值

Ave*_*Joe 1 angular-material2 angular

在这个材料2片段中,我们如何确保具有该draft值的按钮恰好是默认值?文档提及selectedchecked指令,但它们似乎不起作用.

<mat-button-toggle-group #group="matButtonToggleGroup" matInput name="status" [(ngModel)]="status" #field_status="ngModel">
    <mat-button-toggle checked? selected? default? value="draft">
    DRAFT <--how do we set this value to be the default selected/checked one? -->
    </mat-button-toggle>
    <mat-button-toggle value="publish">
    PUBLISH
    </mat-button-toggle>
</mat-button-toggle-group>
Run Code Online (Sandbox Code Playgroud)

Uli*_*lko 5

希望这可以帮助.

public selectedVal: string;
constructor() { }

ngOnInit(){
  this.selectedVal ='draft';
} 

public onValChange(val: string) {
  this.selectedVal = val;
}

 <mat-button-toggle-group #group="matButtonToggleGroup" [value]="selectedVal" (change)="onValChange(group.value)" >
  <mat-button-toggle value="draft">
    Draft
  </mat-button-toggle>
  <mat-button-toggle value="publish">
    Publish
  </mat-button-toggle>
</mat-button-toggle-group>
Run Code Online (Sandbox Code Playgroud)