I'm working with Angular. There is a similar question but not answered -
How to loop through a JSON object with typescript
I'm not getting any error or warning. But I'm not getting the output also. I'm trying to imitate twitter-api. I've created a json object in my typescript and I'm trying to loop through my json in HTML. Here's my code:
twitter-timeline.component.ts
output: JSON;
twitter_data:any = {
statuses: [
{screen_name:"tanzeel", status: "wonderful day, enjoying at beach"},
{screen_name:"pablo", status: "what a lovely morning #surfing #beach #relax"},
{screen_name:"ricky", status: "feeling sick :-( #typhoid"}
]
}
ngOnInit() {
this.output = <JSON>this.twitter_data;
}
twitter-timeline.component.html
<div class="container" *ngFor="let tweets of output; let i=index">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-column">
<p class="screen-name">{{tweets.statuses[i].screen_name}}</p>
<p class="user-status">{{tweets.statuses[i].status}}</p>
<br>
</div>
</div>
</div>
Is there anything wrong with the way I'm creating JSON object, or there's something wrong with the way I'm reading values in HTML. Please correct me.
I also tried this kind of JSON structure:
output: JSON;
obj: any =
{
"col1":{"Attribute1": "value1", "Attribute2": "value2", "Attribute3": "value3"},
"col2":{"Attribute1": "value4", "Attribute2": "value5", "Attribute3": "value6"},
"col3":{"Attribute1": "value7", "Attribute2": "value8", "Attribute3": "value9"}
};