Using expressions in ngModel

243 views
Skip to first unread message

Slava Fomin

unread,
Oct 15, 2015, 4:30:09 PM10/15/15
to AngularJS
Hello there!

I'm trying to use non-trivial expressions inside of ngModel directive in order to generate form elements dynamically (using ngRepeat loop).

However, it's not working as expected.

I've created a minimal Plunk to demonstrate the idea.

Here's the code inside of my controller:

$scope.entity = {
  firstName
: 'Jack',
  lastName
: 'Bauer',
  location
: {
    city
: 'New York'
 
}
};
$scope
.path = 'location.city';

I've managed to display input field correctly with proper value this way:

<input type="text" ng-model="$eval('entity.' + path)">

However, I can't change the value. It's not editable. I'm getting the following error:

Error: ngModelSet is not a function

What could be the reason for this? Is there a way to solve my problem? I need to access property of the object using property path, e.g.: user.location.city.

I will gladly accept any suggestions, thank you!

---

Also, here's the question on SO.

Sander Elias

unread,
Oct 15, 2015, 11:43:07 PM10/15/15
to AngularJS
Hi Slava,

I answered your question on SO. 

Regards
Sander
Reply all
Reply to author
Forward
0 new messages