I have a variable param in scope as $scope.param that is always either foo or bar. I'm creating a table with rows defined by <tr ng-repeat="d in data">.
When I have the following: <td>{{d.foo}}</td> or <td>{{d.bar}}</td> everything works and the data shows up fine. However, when I have <td>{{d.param}}</td> angular can't find anything and the cell is blank.
In other words, I'm trying to access an object value using a variable as the key rather than the key itself. Any idea how to do this?
Use bracket notation:
{{d[param]}}
Related
I have a data object, and i want to get on of the value from it, when i try to print the data:
console.log(data);
i got an object like the image below :
the problem is i want to get the order[billing_address][country_id] which i think is an object, but i don't know how to fetch it. i've tried :
console.log(data.order); //didn't work
console.log(data.order[billing_address][country_id]);//didn't work
The name of the property is: "order[billing_address][country_id]"
To access its value try:
console.log(data['order[billing_address][country_id]'); // Should work
It appears that the values you are looking for have keys that are the whole string:
"order[billing_address][telephone]"
You can access these values like this:
data["order[billing_address][telephone]"] //"5"
You are currently trying this:
data.order[billing_address][country_id]
What you are trying doesn't work because there are no variables billing_address or country_id that are defined, and the object is not that deeply nested - just has the above mentioned long string for a key.
I have a Problem with the AngularJS Scope. I want to use a Variable of it, which contains an Object. In the Object I want one index which is saved in another scope Variable.
So I want something like that:
{{graphdata.nodes._data.{{selectedElements.nodes[0]}} }}
graphdata.nodes._data is the Object, and the index I want is saved in selectedElements.nodes[0]. Can someone help me with that?
You cannot and shouldn't interpolate twice. just write:
{{graphdata.nodes._data[selectedElements.nodes[0]]}}
I have to create a form in which meta data is coming from server . So I can not use hard code variable binding. Say I have a column definition studentcol that has an expression and display name.
$scope.studentcol = {expression:"studentid","display":"name"}
$scope.data = {};
If I use . It get failed. It will work properly either I use hard code expression say data.studentid.display or value for studentid already exists in data then above binding works well
http://plnkr.co/edit/YBt37TuILz1KsPOUAo9q?p=preview
Please suggest
Rohit Bansal
I've got a hbs template where I've got an array of objects and a boolean toggle variable (toggles the template behavior), let's say:
{
objs: list,
mode: true
}
I'm not able to access the mode variable when inside the loop over objs (the context is changed). What I want is to make an if-statement using the upper variable. I found that I can write a custom helper. But is there no other way to access the variable? I also found out, that inside the loop the variable is accessible via {{../mode}} - but still, don't know how to access that.
Finally, I've found a solution:
{{#if ../mode}}xyz{{/if}}
Refer to this example.
I got an array named Header (store name for table header) and another array named Type (store class name for each column). I wonder how to get access to the Type array using Header index.
It appears that in a binding expression like that you need to call $index with brackets, i.e.:
$root.Type()[$index()]
Updated fiddle: http://jsfiddle.net/KuzGf/1/