2

In angularjs I have this code:

<input type="text" ng-model="properties.foreground.value">

I want it to be like:

<input type="text" ng-model="properties.{{type}}.value">

I changed a part of the model input to be a string. It does not work. Can it be done some other way?

1
  • 3
    Try ng-model="properties[type].value">. Commented Mar 10, 2014 at 15:49

1 Answer 1

2

You need to use the bracket notation to access the property and not the dot notation. This is because ngModel binds the attirbute to the scope using =, so the value is not interpolated.

<input type="text" ng-model="properties[type].value">
Sign up to request clarification or add additional context in comments.

4 Comments

what if it's more dynamic than this, a.b.c.d or a.f.g
Then it would be property[a][b][c]
if you look at my example, I have a of b.c.d and a of f.g your answer doesn't work in this case
Open another question and I will answer. It's too difficult in 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.