Disable button in ionic 2


#1

hey guys

if i have an id fro each button :
<button inline id="9" > submit </button>
and i want to compare this id into a specific number if they are equal i want to disable the button

i use ionic 2 ts

Regrads


#2

you can do it in CSS

.dontLink{
pointer-events: none;
}

Add this class to perticular button id using angular 2’s [ngClass]


#3

How are you setting these ids? Are they generated as part of an ngFor loop?


#4

no i just putted like <button clear id="1" >something</button>


#5

That makes things a little more tedious. Assuming you have the target id in your controller, you’ll want something like this:

class MyPage {
  // modify this property to change which button is disabled
  disabledButtonId:string;
}
<button id="1" [disabled]="disabledButtonId == '1'">button 1</button>
<button id="2" [disabled]="disabledButtonId == '2'">button 2</button>