-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngOnInit should never be called twice, even if an error happens #6782
Comments
+1! |
If no one has this yet i can take this on. |
I get the same issue. I tried to pass in the object from one component to another using @input decorator, and using the parameter i build another object in the passed component in ngOninit lifecycle method. In the first iteration i was able to get the value but in the second iteration (which shouldn't happen) reinitialized the values back to null. |
@innoproject Could you create a plunker? |
I'm trying to use leaflet library an add a map to a component. It seems like the ngOnInit is called twice which is causing an issue to the map instantiation. Is there any workaround to this issue ? |
@ihrimech Try to reproduce in a Plunker. Thanks (& include version info in your comments) |
Can't reproduce it anymore. I've put it in a try-catch block meanwhile so I could go forward with the app development and now It seems to be working fine without. I'll keep it like this and make a plunker when the problem gets back. |
Hi, Please look into this. I just want to skip second time call. I cant create plunkr but i shared my Component code below. `import {Component,OnInit,Input,ElementRef} from '@angular/core'; @component({ export class DateTimePickerComponent implements OnInit{ @input() public dateAndTime:Boolean; /**
|
@tbosch so what is work around for this issue to skip second time call? |
Still reproducible with 2.0.2 |
I get the same issue. I tried to pass in the object from one component to You are receiving this because you are subscribed to this thread. |
@francosioquim @prabhatsharma @DILEEPKUMAREBIX We really need a plunker that shows it. Otherwise it is super hard to reproduce your problem... |
@francosioquim for me inputs were undefined not null (on the retriggered onInit) |
Hi, Well the Problem in my case was the way I was bootstrapping the Child Components. @NgModule({ |
Thanks @amardeep157 ! Solved my problem. |
Still reproducible in 4.0.0, but due the nature of our project (relatively big) it's very hard to find where the error happens. |
In my case I was using template driven forms. Switched to model driven
forms and issue disappeared.
…On Tue, Apr 11, 2017, 11:38 AM Javascript developer < ***@***.***> wrote:
Still reproducible in 4.0.0, but due the nature of our project (relatively
big) it's very hard to find where the error happens.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6782 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEC7DISVRUk0NJ7kix2QPIueH2tyj3o0ks5ru6yAgaJpZM4HPsCE>
.
|
The problem is that we cannot grab the original error. If someone could give a good advice how to catch the original error it would be great. |
We are also experiencing the problem. It is like routerLinkActive reinitializes the component. |
This still happens in production mode, tracking here: #15925 |
@razvanmitre I face the same issue with |
I have deleted routerLinkActive, but still happens |
Any updates on this issue? |
still have same trouble. |
Same trouble here |
I am also facing the same issue, the constructor is getting called twice. I have created a thread here. does anyone have any workaround for this? |
I was facing the same issue a while ago. Looks like, Angular 'nativeNode' is not destroyed properly, I was using the same selector name for creating customElements and component selector. During app startup 'ERROR TypeError: Cannot read property 'nativeNode' of null' shows up in the console, from what I understand angular tries 2nd time if it fails the 1st time, when angular tries the 2nd time it looks like it resolves the error. Try differentiating selector names between @component({selector: ''}) and createCustomElement(). If you are creating custom elements, it should help. That's the fix I had for now, at least it worked for me. |
2019 and still same issue. Constructor and NgOnInit called twice |
Yep, still happens, ngOnInit and constructor fired twice just a per website is starting. Very disappointing, as it seems not possible to avoid it |
You can avoid such thing by enabling PROD mode
…On Tue, Sep 17, 2019 at 2:56 PM dalvarezsmiet ***@***.***> wrote:
Yep, still happens, ngOnInit and constructor fired twice just a per
website is starting. Very disappointing, as it seems not possible to avoid
it
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6782?email_source=notifications&email_token=AD3Q3VRBFBX6CRRBXJCDEETQKCPEDA5CNFSM4BZ6YCCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD634UOA#issuecomment-532138552>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD3Q3VTQ2PU5ENVBASTHRTTQKCPEDANCNFSM4BZ6YCCA>
.
|
No way, production mode is already enabled in my project, and the ngOnInit is being fired twice, always. I've read about some binding errors or HTML non-closed tags that may cause this behavior, but I've checked it, and it's not the case... It's really weird |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Right now, if an error happens during detecting changes of content/view children of a component,
ngOnInit
will be called twice (seen inDynamicChangeDetector
).This can lead to follow up errors that hide the original error.
/cc @matanlurey
The text was updated successfully, but these errors were encountered: