1

I have scope in controller: $scope.readOnly = true then I have code in html:

  <select ng-if="readOnly" ng-model="readOnly" required>
     <option value="true" selected>True</option>
     <option value="false">False</option>
  </select>

 <select ng-if="!readOnly" ng-model="readOnly" required>
     <option value="true">True</option>
     <option value="false" selected>False</option>
 </select>

<button ng-click="save()"> Save</button>

but it doesn't work fine :/ on click save, the result is undefined :/ how to make this correct?

5
  • 1
    can you please post more of your HTML code and the JS controller as well? Commented Jan 7, 2016 at 12:15
  • @Ironcar Driftman, Initialize $scope.doc.readOnly to true instead of specifiying selected in option. Commented Jan 7, 2016 at 12:17
  • Please add controller and complete HTML or share it as a plunkr Commented Jan 7, 2016 at 12:19
  • @RajKantaria Initialize $scope.doc.readOnly dosen't work, because you must to initialize $scope.doc as an object. Correct initialize: $scope.doc = { readOnly: true }; Commented Jan 7, 2016 at 12:28
  • jsfiddle.net/kakv0huf/1 Commented Jan 7, 2016 at 12:50

1 Answer 1

1

Try do this in this way:

<select ng-model="doc.readOnly">
   <option value=true>True</option>
   <option value=false>False</option>
</select>

Example

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

3 Comments

paste an example in jsfiddle.net
jsfiddle.net/kakv0huf/1
it doesn't work in my code and can you come in my computer with team viewer?

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.