comment.component.ts:
import { Component, OnInit } from \'@angular/core\';
import { Router} from \'@angular/router\'
import { Comment } from
I have found a solution of my issue using Zone and promise.
below is the update code of the "comments.component.ts".
by using zone.run(), I am able to bind data with HTML when
"comments.component" is loaded.
Is this a correct way to bind data with HTML if data is coming using api?
import { Component, OnInit, NgZone } from '@angular/core'; //NgZone *
import { Router} from '@angular/router'
import { Comment } from 'comment entity path'
import {CommentService} from 'comment service path'
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/toPromise' // *
@Component({
template: ` 0">
- {{item.Name}}
`
})
export class CommentComponent implements OnInit {
comments: comment[]=[]; // *
constructor(private router: Router, private commentService: CommentService, private zone: NgZone) {
}
ngOnInit() {
this.zone.run(() => {
this.getComments().toPromise().then((data) => {
this.comments= data || [];
});
})
}
getComments() {
return this.commentService.getComments();
}
}