i'm newcomer angular2, i'm used angular 1 digest cycle, meaning if update scope of view can manually trigger digest calling $scope.$digest()
. however, i'm not sure how in angular2, esp given new framework doesn't have implicit data binding old version had.
here's problem. have route loads component when url parameter hit:
// router export const approutes : routerconfig = [ { path: 'my/:arg/view', component: mycomponent } ]
then have component:
// component export class mycomponent { constructor(private route : activatedroute, private r : router) { let id = parseint(this.route.params['value'].id); console.log(id); // stuff id } reloadwithnewid(id:number) { this.r.navigatebyurl('my/' + id + '/view'); } }
lets navigate url /my/1/view
. call constructor , number 1
logged. however, if call reloadwithnewid
new id, reloadwithnewif(2)
, constructor not called again. how manually reload component?
there shouldn't need reload component. update model , view updates itself:
export class mycomponent { constructor(private route : activatedroute, private r : router) {} reloadwithnewid(id:number) { this.r.navigatebyurl('my/' + id + '/view'); } ngoninit() { this.sub = this.route.params.subscribe(params => { this.paramschanged(params['id']); }); } paramschanged(id) { console.log(id); // stuff id } }
Comments
Post a Comment