Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable an input box using angular.js

I am using this field for an edit view and a create view

<input data-ng-model="userInf.username"  class="span12 editEmail" type="text"  placeholder="[email protected]"  pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" required /> 

in the controller I have this code to disable the input element:

function($rootScope, $scope, $location, userService) {  //etc      $(".editEmail" ).attr("disabled", disable);  // no idea how to do in angular } 

Please help.

like image 442
Prashobh Avatar asked Jul 01 '13 10:07

Prashobh


People also ask

How do I disable input textbox?

We can easily disable input box(textbox,textarea) using disable attribute to “disabled”. $('elementname'). attr('disabled','disabled'); To enable disabled element we need to remove “disabled” attribute from this element.

How do you disable enable a textbox input when radio button is selected deselected in angular?

Essentially what you really need is to implement a toggling function that changes a boolean type variable whenever the radio button is clicked. Then bind this variable to the disabled attribute of the input text box.


2 Answers

Use ng-disabled or a special CSS class with ng-class

<input data-ng-model="userInf.username"          class="span12 editEmail"         type="text"          placeholder="[email protected]"          pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"         required         ng-disabled="{expression or condition}" /> 
like image 78
EpokK Avatar answered Sep 25 '22 04:09

EpokK


You need to use ng-disabled directive

<input data-ng-model="userInf.username"         class="span12 editEmail"         type="text"         placeholder="[email protected]"         pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}"         required         ng-disabled="<expression to disable>" /> 
like image 27
Arun P Johny Avatar answered Sep 21 '22 04:09

Arun P Johny