Search code examples
angularjsangularjs-ng-options

AngularJS 1.4.0-rc.2 ngOptions disable when


OK, so I decided I was going to do a pre-release Angular to take advantage of the new "disable when" inside of the ngOptions. I'm not sure of the scope I'm allowed to fiddle with. Here is code that works as expected one varable removed:

        <select multiple ng-model="CoBorrowerIds" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) disable when (person.Id==1) for person in Persons"></select>

The array with id of 1 is disabled. However, I have this code that does not work:

        <select ng-model="BorrowerId" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) for person in Persons"></select>

        <select multiple ng-model="CoBorrowerIds" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) disable when (person.Id==BorrowerId) for person in Persons"></select>

So my question is: do I have access to the scope inside of "disable when"? If I do, what am I doing wrong?


Solution

  • I decided to add a ng-repeat statement to the parent element, creating a need to explicitly define the scope. It now reads:

            <select ng-model="loan.BorrowerId" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) for person in Persons" class="form-control"></select>{{BorrowerId}}
    
            <select multiple ng-model="loan.CoBorrowerIds" ng-options="person.Id as (person.LastName + ', ' + person.FirstName) disable when (person.Id==loan.BorrowerId) for person in Persons" class="form-control"></select>
    

    ...and it works fine. It may be a bug, or my poor thinking. However, for what it's worth, there's the answer!