javascript - having problems setting a member variable on an ng2 component -
i'm having problems setting member variable on ng2 component. in component below, i'm trying set service results member variable. updatesearchresults1() sets member variable expected updatesearchresults2 delegates promise processsearchresults returns error: "typeerror: cannot set property 'blogpostlistitems' of null." understanding these 2 implementations functionally same. why can set this.blogpostlistitems updatesearchresults1() whereas error this.blogpostlistitems null updatesearchresults2()?
import { component, oninit, viewchild, elementref } '@angular/core'; import { router } '@angular/router'; import { blogservice } '../../services/blog.service'; import { bloglanding } '../../entities/blog-landing'; import { response } '@angular/http'; @component({ selector: 'blog-landing', templateurl: '../../../ng2/templates/blog-landing.component.html' }) export class bloglandingcomponent implements oninit { @viewchild('ddlauthor') ddlauthor; bloglanding: bloglanding; blogpostlistitems: array<object>; constructor( private router: router, private blogservice: blogservice){} ngoninit(): void { } updatesearchresults1() { this.blogservice .getblogposts() .then(blogpostlistitems => this.blogpostlistitems = blogpostlistitems) } updatesearchresults2() { this.blogservice .getblogposts() .then(this.processsearchresults); } processsearchresults(responseobject) { this.blogpostlistitems = responseobject; } }
Comments
Post a Comment