1

I am trying to check multiple values in ng-disabled.

I am trying

ng-disabled = "{{ (id === po.adm_sid) ||  (sid === po.opm_sid) }}"

which doesn't work. It works when I check a single value. I also tried:

ng-disabled = "{{ id === (po.adm_sid ||  po.opm_sid) }}"
5
  • Stupid question (mine). Are you sure that at least one of the two tests case are true? :) Commented Aug 26, 2016 at 12:48
  • Do You want to disable element when both conditions are True, or at least one of them? Commented Aug 26, 2016 at 12:51
  • 1
    take out {{}}. ngDsabled attribute evaluates expressions. So no need of {{}}. More details here docs.angularjs.org/api/ng/directive/ngDisabled Commented Aug 26, 2016 at 13:02
  • I want to check if id is equal to atleast one of them! @anirudh didn't work even without a {{ }} Commented Aug 26, 2016 at 13:19
  • Is it possible to create a plinkr or something....As per my understanding data-ng-disabled="id===po.adm_sid || id === po.opm_sid" should work.....It might seem silly but i think there is a typo in your question...in the first scenario you are checking sid and in second just the id.... Commented Aug 26, 2016 at 13:25

1 Answer 1

3

I would make a helper function and not have multiple checks in the html. Something like:

ng-disabled = "isDisabled()" 

$scope.isDisabled = function(){
   return (id === po.adm_sid) || (sid === po.opm_sid);
}

I usually have better luck with this kind of set up for multiple value checking in the html

Sign up to request clarification or add additional context in comments.

1 Comment

Then you can test the function too! Hooray for unit tests!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.