Olivier Catteau
Olivier Catteau

Reputation: 64

Evaluate an expression in AngularJs template

I have a little problem with an AngularJs template I would like to evaluate something like this :

<span>{{myObject[prop]}}</span>

When I have a controller such like this :

$scope.myObject = { code: "1", value: "foo" };
$scope.prop = 'value';

In fact, I would like to dynamically retrieve a property of an object in a template. Here I would like to bind "myObject.value".

Thanks for your help !

Upvotes: 0

Views: 319

Answers (2)

noypi
noypi

Reputation: 991

{{ myObject[prop] }}

...

$scope.myObject = angular.fromJson( $templateCache.get('mytemplate') )
$scope.prop = 'a_prop_from_template_object';

Upvotes: 0

user3722785
user3722785

Reputation: 216

you can do this in this

<span>{{prop}}</span>

$scope.myObject = { code: "1", value: "foo" };
$scope.prop=$scope.myObject.value;

Upvotes: 3

Related Questions