Angular material slide toggle

Angular material slide toggle DEFAULT

mat-slide-toggle in Angular material

Angular Material is a UI component library that is 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. 

mat-slide-toggle is a kind of switch or button that is used to toggle between states like one and off or true or false.

Installation syntax:

ng add @angular/material

Approach:

  • First, install the angular material using the above-mentioned command.
  • After completing the installation, Import ‘MatSlideToggleModule’ from ‘@angular/material/slide-toggle’ in the app.module.ts file.
  • Then use the mat-slide-toggle tag to display a toggle button.
  • And in order to write the significance of that button then we need to mention it between the opening and closing tags.
  • If we want to change the theme then we can change it by using the color property. In angular we have 3 themes, they are primary, accent, and warn.
  • Once done with the above steps then serve or start the project.

Code Implementation:



app.module.ts:

Javascript

 
 

app.component.html:

HTML

Output:




My Personal Notesarrow_drop_up
Sours: https://www.geeksforgeeks.org/mat-slide-toggle-in-angular-material/

Slide toggle

NameDescription

Used to set the aria-label attribute on the underlying input element.

@Input('aria-labelledby')

Used to set the aria-labelledby attribute on the underlying input element.

Whether the slide-toggle element is checked or not.

Theme color palette for the component.

Whether ripples are disabled.

Whether the component is disabled.

A unique id for the slide-toggle input. If none is supplied, it will be auto-generated.

Whether the label should appear after or before the slide-toggle. Defaults to 'after'.

Name value will be applied to the input element if present.

Whether the slide-toggle is required.

An event will be dispatched each time the slide-toggle changes its value.

An event will be dispatched each time the slide-toggle is dragged. This event is always emitted when the user drags the slide toggle to make a change greater than 50%. It does not mean the slide toggle's value is changed. The event is not emitted when the user toggles the slide toggle to change its value.

An event will be dispatched each time the slide-toggle input is toggled. This event is always emitted when the user toggles the slide toggle, but this does not mean the slide toggle's value has changed. The event does not fire when the user drags to change the slide toggle value.

Returns the unique id for the visual hidden input.

Sours: http://man.hubwiz.com/docset/Angular.docset/Contents/Resources/Documents/material.angular.io/components/slide-toggle/api.html
  1. Brothertown tribe
  2. Glider chair cushions
  3. Rv dealer missouri

Angular Material 7 - Slide Toggle



The <mat-slide-toggle>, an Angular Directive, is used as a on/off switch with material design styling and animation capabilities.

In this chapter, we will showcase the configuration required to draw a slide toggle control using Angular Material.

Create Angular Application

Follow the following steps to update the Angular application we created in Angular 6 - Project Setup chapter −

StepDescription
1Create a project with a name materialApp as explained in the Angular 6 - Project Setup chapter.
2Modify app.module.ts, app.component.ts, app.component.css and app.component.html as explained below. Keep rest of the files unchanged.
3Compile and run the application to verify the result of the implemented logic.

Following is the content of the modified module descriptor app.module.ts.

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; import {MatSlideToggleModule, MatCheckboxModule} from '@angular/material' @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatSlideToggleModule, MatCheckboxModule, FormsModule, ReactiveFormsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }

Following is the content of the modified HTML host file app.component.html.

<mat-slide-toggle class = "tp-margin" [checked] = "checked" [disabled] = "disabled"> Slide! </mat-slide-toggle> <section class = "tp-section"> <mat-checkbox class = "tp-margin" [(ngModel)] = "checked">Checked</mat-checkbox> <mat-checkbox class = "tp-margin" [(ngModel)] = "disabled">Disabled</mat-checkbox> </section>

Following is the content of the modified CSS file app.component.css.

.tp-section { display: flex; align-content: center; align-items: center; height: 60px; } .tp-margin { margin: 30px; }

Following is the content of the modified ts file app.component.ts.

import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'materialApp'; disabled = false; checked = false; }

Result

Verify the result.

Slide Toggle

Details

  • As first, we've created two check boxes using mat-checkbox and bind them using ngModel with variables. These properties will be used to handle the slide toggle.

  • Then, we've created the slide toggle and showcased its various attributes bound with variables in .ts file.

Sours: https://www.tutorialspoint.com/angular_material7/angular_material7_slider_toggle.htm
Angular Material Slide Toggle

.

Slide toggle material angular

.

Angular Material Slide Toggle Show Hide Div

.

You will also like:

.



1054 1055 1056 1057 1058