Questions tagged ngoninit

Explore the latest questions and answers asked by our top developers.

Route parameters – subscribe method

"Angular does not create the component if it is already present in the DOM. It reuses the component instance. This implies that the ngOnInit life cycle hook is not invoked when the user navigates to the component again." Based on this, I cannot understand why ngOnInit lifecyle method is invoked again if it contains the […]

Angular, calling Method in ngOnInit with Store Element (Subscribe)

Using a store, I subscribed to all the changes for a particular item. I want to output these changes (terminal message) in an angular component (ng-terminal). The code completion suggests me the method write. This also works outside of ngOnInit(). The output via the Console works. The control is also present (this.terminal != null). H […]

By Holgis
Categorized as angular, ngoninit, store, subscribe Tagged , , ,

Angular ngOnchanges calls method, but method does not call service or output results

I am confused by what is happening in a section of my app. I have a component that uses ngOnChanges. ngOnchanges fires right before ngOnInit when the component loads. Both ngOnChanges and ngOnInit call a certain method (fetchResults) that calls an api service to get some data using an observable return. I have a tap […]

By mo maat
Categorized as angular, ngonchanges, ngoninit Tagged , ,

Angular call function inside fetch (ngOninit)

I want to call a function inside a fetch, but for some reason I get the following error and can’t find a solution. Uncaught (in promise): TypeError: Cannot read properties of undefined (reading ‘myFunction’) TypeError: Cannot read properties of undefined (reading ‘myFunction’) How I should call a function inside the fetch -> then ? Minimalist […]

Angular 7 – ngOnInit – window.location.href not working – From HTTPS to HTTP

I have following piece of code in my ngOnInit event. ngOnInit() { let Url = window.location.href.trim().toLocaleLowerCase(); if (Url.startsWith("https://")) { console.log(‘HTTPS’); let NewUrl = Url.replace("https://", "http://"); this.document.location.href = NewUrl; } } My aim is that if Url is having HTTPS then I need to redirect to same Url but with HTTP. But this piece of code […]

By Gulfam
Categorized as angular, ngoninit, redirect, window.location Tagged , , ,

ngFor not listing all data received from ngOnInit API call

so I am relatively new to Angular and I have inherited some code from someone else. I’m having an issue regarding the view not displaying data correctly that is received by an API call in the ngOnInit function. Below is basically a pseudo-code that describes in a simple way what the code is doing. I […]

By Daniel Boyd
Categorized as angular, angularjs, ngfor, ngoninit, typescript Tagged , , , ,

Why is angular saying my object can be null when creating in ngOnInit?

Creating a form in the component: export class LoginPageComponent implements OnInit { form!: FormGroup constructor() { } ngOnInit() { this.form = new FormGroup({ email: new FormControl(null, [Validators.required,]), password: new FormControl(null, [Validators.required, Validators.minLength(6)]), }) } } In html, I perform value input checks <div *ngIf="form.get(’email’).touched && form.get(’email’).invalid" class="validation"> <small *ngIf="form.get(’email’).errors.required">Enter Email</small> <small *ngIf="form.get(’email’)">Enter valid Email</small> […]

By Alex
Categorized as angular, ngoninit, typescript Tagged , ,

Adding a Loading Screen for AppComponent ngoninit

I have some authentication and other startup services being called on ngoninit for app.component.ts so that the screen remains black before moving to the homepage. I created a loader service that will display a loading page while its active, however I am still seeing the black screen app.component.ts ngOnInit(){ this.loaderService.showLoader; //startupservice calls and auth calls […]

By Carbylicious
Categorized as angular, ngoninit Tagged ,

Why my app component ngOnInit called twice?

i see problem in my angular project,on some pages i didn’t understand why request were made twice on page refresh. i noticed that the init was called twice in my components. I thought to myself that this was going to be a complicated problem given the size of the project which contains a lot of […]

By Nicolas M
Categorized as angular, init, ngoninit, router Tagged , , ,

How to update scrolltop after check

My question is: how can I still update the [scrolltop] after the check without getting the error? Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for ‘scrollTop’: ‘260’. Current value: ‘300’. I have a variable where I push data in and because of that the variable string gets longer and longer and […]

By Ranhousecode
Categorized as angular, css, html, ngoninit, scrolltop Tagged , , , ,
1 5

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us