angularjs - ngOnInit method called twice -


i'm little bit new in angular:

when load angular application (angular 4), specific component's ngoninit() method called if wasn't rendered. after navigate app route renders component, ngoninit() called again. why that? kind of error, or how works? there no error in console.

(because of this, in component's ngoninit() subscribe method runs twice.)

update:

offer-info.component.ts:

import { component, input, oninit, ngzone } '@angular/core';  import { offerservice } './offer.service'; import { offer } '../models';  declare var $: any;  @component({     moduleid: module.id,     selector: 's2a-offer-info',     templateurl: './offer-info.component.html', }) export class offerinfocomponent implements oninit {      private zone: ngzone;     offer: offer = null;      constructor(         private offerservice: offerservice,     ) { }      ngoninit() {         //this 2 'test' output on console:         console.log('test');         this.zone = new ngzone({enablelongstacktrace: true});         this.offerservice.getofferforofferinfo().subscribe((offer: offer) => {             if (offer !== null) {                 this.zone.run(() => {                     this.offer = offer;                     $('#s2aofferinfomodal').modal();                 });             }         });     }  } 

in page-packages.component.html:

... <!-- tag appers once in whole application: --> <s2a-offer-info></s2a-offer-info> ... 

in app-routing.module.ts:

...   { path: 'packages', component: pagepackagescomponent, canactivate: [loggedinguard] },   { path: 'search', component: pagesearchcomponent, canactivate: [loggedinguard] },   { path: '', redirectto: '/search', pathmatch: 'full' }, ... 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -