ANGULAR2 the page data is not refreshed after the HTTP request returns data

Source: Internet
Author: User

The data returned after a request with HTTP is updated, but the data for the bound page is not refreshed, and after finding it, it is found that the change detection changedetectorref can be used for detection refresh.

Official Document Description: Changedetectorref

The application code is as follows:

Import {component,ngmodule,changedetectorref, oninit}from ' @angular/core '; Constructor (Private CDR : Changedetectorref) {}getcommentitemsfunc () {    this. Commentservice.getcommentitems(ID  )      = =        {this. commentitems = commentitems        ;  This.cdr.markForCheck ();        this. cdr.detectchanges ();      })  }    

Note : To be in This.cdr.markForCheck (); Then add this.cdr.detectChanges (); Otherwise, the data on the page will not be refreshed.

end!

ANGULAR2 the page data is not refreshed after the HTTP request returns data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.