How to disable the button in Angular

How to disable the button in Angular

In this post we will give you information about How to disable the button in Angular. Hear we will give you detail about How to disable the button in AngularAnd how to use it also give you demo for it if it is necessary.

we are going to learn about how to disable or enable the HTML button element in an angular app.

Disabling the button

We can disable a button by passing the boolean value true to the disabled attribute.

app.component.html
<button [disabled]="isDisabled">Subscribe</button>
app.component.ts
import { Component } from '@angular/core';@Component({  selector: 'app-root',  templateUrl: './app.component.html',  styleUrls: ['./app.component.css']})export class AppComponent {  isDisabled = true;}

To enable it back, we need to set the isDisabled property value to false.

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

Disabling the button when input field is empty

We can also disable the button conditionally when an input field value is empty and enable it back if it has some data.

Example:

app.component.html
<input type="email" placeholder="Email" [(ngmodel)]="email" /><button [disabled]="!email.length">Subscribe</button>
app.component.ts
import { Component } from '@angular/core';@Component({  selector: 'app-root',  templateUrl: './app.component.html',  styleUrls: ['./app.component.css']})export class AppComponent {  email = '';}

Hope this code and post will helped you for implement How to disable the button in Angular. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US