Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any alternative for ng-disabled in angular2?

I am using angular2 for development and was wondering if there is any alternative for ng-disabled in angular2.

For ex. below code is in angularJS:

<button ng-disabled="!nextLibAvailable" ng-click="showNext('library')" class=" btn btn-info btn-xs" title="Next Lib >> {{libraries.name}}">
    <i class="fa fa-chevron-right fa-fw"></i>
</button>

Just wanted to know How can I achieve this functionality? any inputs?

like image 854
Bhushan Gadekar Avatar asked May 11 '16 10:05

Bhushan Gadekar


People also ask

How do you write if condition in NG-disabled?

Or you can use ng-disabled="condition1 || condition2" , is depend of you logic conditional.

What is Ng-disabled in angular?

The ng-disabled Directive in AngularJS is used to enable or disable the HTML elements. If the expression inside the ng-disabled attribute returns true then the form field will be disabled or vice versa. It is usually applied on the form field (i.e, input, select, button, etc).


3 Answers

To set the disabled property to true or false use

<button [disabled]="!nextLibAvailable" (click)="showNext('library')" class=" btn btn-info btn-xs" title="Next Lib"> {{libraries.name}}">
    <i class="fa fa-chevron-right fa-fw"></i>
</button>
like image 145
Günter Zöchbauer Avatar answered Oct 08 '22 19:10

Günter Zöchbauer


[attr.disabled]="valid == true ? true : null"

You have to use null to remove attr from html element.

like image 76
Roger Gusmao Avatar answered Oct 08 '22 19:10

Roger Gusmao


Here is a solution am using with anular 6.

[readonly]="DateRelatedObject.bool_DatesEdit ? true : false"

plus above given answer

[attr.disabled]="valid == true ? true : null"

did't work for me plus be aware of using null cause it's expecting bool.

like image 13
Aneeq Azam Khan Avatar answered Oct 08 '22 19:10

Aneeq Azam Khan