0

when user open modal window i am calling rest service to get boolean flag that is data in below code, Now if that flag is true i want to disable option in ng-options where id is RA_ATTST_LANGUAGE. How can i disabled dropdown option based on below logic ?

main.html

<select name="adminNotificationTypeCode" class="form-control" ng-model="messageNotificationDTO.adminNotificationTypeCode" required id="adminNotificationTypeCode" ng-change="attestationCheck()" ng-options="adminDataSource.id as adminDataSource.text disable when adminDataSource.id == 'RA_ATTST_LANGUAGE' && disableRA_ATTST_LANGUAGE for adminDataSource in adminDataSource">
                            <option value="">Select...</option>
                        </select>

main.js

function getAttestationLanValidation (){
          MessageAdminNotificationFactory.getAttestationLanValidation().then(function(response){
            if(response){
              $scope.disableRA_ATTST_LANGUAGE = response.data;
            }
          });
        };

           //Add new Notification
           $scope.addMessageNotification = function() {
               $scope.messageNotificationModal.open().center();
               $scope.clearNotificationForm();
               getAttestationLanValidation();
           };

dropdown.json

[{
    "uid": null,
    "index": 0,
    "selected": null,
    "expanded": null,
    "id": "RA_PLTFRM_NOTIF",
    "text": "Platform Maintenance Notification",
    "parentId": null,
    "items": null
}, {
    "uid": null,
    "index": 0,
    "selected": null,
    "expanded": null,
    "id": "RA_ATTST_LANGUAGE",
    "text": "Attestation Language",
    "parentId": null,
    "items": null
}]

2 Answers 2

3

*Edited due to further explanation

try updating your ng-options attribute to this:

 ng-options="adminDataSource.id as adminDataSource.text disable when adminDataSource.id == 'RA_ATTST_LANGUAGE' && disableRA_ATTST_LANGUAGE for adminDataSource in adminDataSource"

you will want to create a Boolean member to your scope that you set to true or false depending on the rest result.. I called it $scope.disableRA_ATTST_LANGUAGE

Plunker for demonstration

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

5 Comments

its not based on id its based on boolean value data if rest service response is true then we will disabled RA_ATTST_LANGUAGE from dropdown
but it looks like you are disbaling whole dropdown option i just want to disable option that is part of dropdown
got this error Error: [$parse:syntax] Syntax Error: Token 'disable' is an unexpected token at column 22 of the expression [adminDataSource.text disable when adminDataSource.id == 'RA_ATTST_LANGUAGE' && disableRA_ATTST_LANGUAGE] starting at [disable when adminDataSource.id == 'RA_ATTST_LANGUAGE' && disableRA_ATTST_LANGUAGE] updated question
What version of angular are you guys using? The disable attribute was added in 1.4.something.
we are using angular 1.3
0

Assuming everything else is correct in your code, and that your service is making a single call per instance in your dropdown.json; If you only need to know if data is present and don't need to get the actual data content, a quick-and-dirty way is to just store the name in an array and check for presence of the id in that array using the ng-disabled directive. Your variable names were confusing, so I just genericized them and called the source array for your select options "items"

Your js needs something like this

 // create an empty array when initializing
    $scope.thatArrayOfIdsThatHaveData = [];
    function getAttestationLanValidation() {
      MessageAdminNotificationFactory.getAttestationLanValidation()
          .then(function(response) {
            var data = response.data;
            console.log('attestation', data);
            if (data) {
              thatArrayOfIdsThatHaveData.push(id);
            }
      });
    };

In your template something like this:

<select ng-model="messageNotificationDTO.adminNotificationTypeCode"
        ng-change="attestationCheck()">
  <option value="">Select...</option>
  <option ng-repeat="item in items" 
          value="item.id"
          ng-disabled="thatArrayOfIdsThatHaveData.indexOf(item.id)>=0">{{ item.label }}</option> 
</select>

Comments

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.