0

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 !

2
  • Your example works fine.... Commented Sep 4, 2014 at 7:37
  • Thanks. Yes, it works fine. Too much beers for me... ;-) Commented Sep 4, 2014 at 7:55

2 Answers 2

3

you can do this in this

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

$scope.myObject = { code: "1", value: "foo" };
$scope.prop=$scope.myObject.value;
Sign up to request clarification or add additional context in comments.

2 Comments

myObject[0] is undefined, myObject is an object not an array :/
Wawy you can check this one actually i trie it in console.
0
{{ myObject[prop] }}

...

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.