1

is it possible to edit directly in an input tag the value of the ng-Model if the latter is a string value ?

This is the JavaScript object:

fields: [
 {id: 5, 
  name: "boolean", 
  type: "BOOL", 
  value: "true"
}]

This is the html code

<input  class="" type="checkbox" ng-model="line.value" data-ng-checked="line.value"/>

The goal would be to directly edit the html tag without modifying the json file.

By avoiding having the following error message

"Error: ngModel:nonassign Non-Assignable Expression"

if you have a solution?

cordially

4
  • If you have some code causing an error, and you wonder why, post the code and ask why. Yes, it's possible. But that won't help you. Commented Apr 28, 2019 at 19:07
  • @JB Nizet re-read the question the problem is due to the fact that the value is a string and not a boolean. I ask if it is possible to change the string value in boolean directly in the ng-model Commented Apr 28, 2019 at 19:12
  • 2
    Don't use ng-model and ng-checked together. Use ng-model for two-way binding. Use ng-checked for one-way binding. Read AngularJS input type=checkbox Directive API Reference Commented Apr 28, 2019 at 19:15
  • 1
    As you can see here: jsfiddle.net/5ejbozkc, using your code allows having a checkbox that doesn't cause the error you get. So, once again, if you want us to explain why you get this error, post a complete minimal example reproducing it. Commented Apr 28, 2019 at 19:27

1 Answer 1

2

To use string values with a checkbox:

<input type="checkbox" ng-model="line.value"
       ng-true-value="'true'" ng-false-value="'false'" />

To use string literals, use single-quotes (') inside double-quotes ("). Otherwise the AngularJS will parse them as a Boolean type.

For more information, see

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

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.