callmekatootie
callmekatootie

Reputation: 11228

How to assign an expression to a model?

I am having the following set up inside an ng-repeat directive:

<span ng-model="d.attr3">
    {{d.attr2 - d.attr1}}
</span>

d is the variable used inside ng-repeat.

My issue is that I expect d.attr3 to hold the value of the expression inside span tag. However, it holds the expression NaN.
Note that I have converted the d.attr1 and d.attr2 values to integers - In fact, the expression evaluates correctly but it is not bound to the scope - how do I get d.attr3 to hold the value of the expression?

Upvotes: 0

Views: 468

Answers (1)

pkozlowski.opensource
pkozlowski.opensource

Reputation: 117370

<span ng-init="d.attr3 = d.attr2 - d.attr1">
    {{d.attr3}}
</span>

Upvotes: 2

Related Questions