angular - In javascript, use object['property string']. How can I do like that in AngularJS 2? -


i have 2 objects. object {'id': 'abc', 'pwd': 'pwd1'} , b object array. b string of object property. this. ['id', 'pwd']

i want use @ ng2 component template.

*ngfor(#str of b)    {{a[str]}} 

but not working.. how can javascript? ng2 using {{object.property}}.

i don't know how can use javascript!

++ edit vote..

template: '<tr *ngfor="#str of b">     <th>{{str}}</th>     <td>{{a[str]}}</td> </tr>'  export class @@{     = [{'id': '1', 'pwd': 'pwd1'}];     b = ['id', 'pwd']; } 

i use that. don't showing values. how can do???

the following code works me:

@component({   selector: 'my-app',   template: `     <div *ngfor="let str of b">       {{a[str]}}     </div>   ` }) export class app {   = {'id': 'abc', 'pwd': 'pwd1'}   b = ['id', 'pwd']; } 

see plunkr: https://plnkr.co/edit/yqkzjs9uapetmo2bkf4e?p=preview.

edit

be careful use ticks if want define string on several lines (and not single quotes). in case template attribute of component.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -