How to create mat-button-toggle-group as read only mode in AngularJS ?
Last Updated :
30 Nov, 2020
Angular Material is a UI component library developed by the Angular team to build design components for desktop and mobile web applications.
In order to install it, we need to have angular installed in our project, once you have it, you can enter the below command and can download it.
Installation syntax:
ng add @angular/material
Approach:
- First, install the angular material using the above-mentioned command.
- After completing the installation, Import ‘MatButtonToggleModule,’ from ‘@angular/material’ in the app.module.ts file.
- Then use <mat-button-toggle-group> and </mat-button-toggle> tags to create angular button toggle group.
- As the MatButtonToggleModule doesn’t consist of read-only property, we can use the disabled property to make it read-only.
- Once done with the above steps then serve or start the project.
Code implementation:
app.module.ts:
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule } from
'@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { AppComponent } from './app.component' ;
import { BrowserAnimationsModule } from
'@angular/platform-browser/animations' ;
import { MatButtonModule } from
'@angular/material/button' ;
import { MatButtonToggleModule } from
'@angular/material/button-toggle' ;
@NgModule({
imports: [ BrowserModule,
FormsModule,
BrowserAnimationsModule,
MatButtonModule,
MatButtonToggleModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
|
app.component.html:
HTML
< mat-button-toggle-group name = "techno"
aria-label = "technology" >
< mat-button-toggle value = "html" >
HTML
</ mat-button-toggle >
< mat-button-toggle disabled value = "css" >
CSS
</ mat-button-toggle >
< mat-button-toggle value = "javascript" >
Javascript
</ mat-button-toggle >
< mat-button-toggle value = "jquery" >
Jquery
</ mat-button-toggle >
</ mat-button-toggle-group >
|
Output:
Observation: If you clearly observe the above output, you can understand that you can’t select and it is the way how read-only property looks like.
Share your thoughts in the comments
Please Login to comment...