Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70435

Provider initialized twice

$
0
0

@smedcalf wrote:

I recently converted my Ionic 2 app to Ionic 3 implementing lazy loading for my pages. Other than adding modules for each page, I did not modify the code/logic.

Now I am running into an issue where I have a basic feedback form occasionally submitting twice to my API service backend. It does not happen every time but definitely more frequently when running on a device vs the browser. After adding logging, I noticed my feedback provider that handles the API Post is initializing twice when the feedback page is opened.

I’ve tried moving the provider to be declared in the app module as well as within the page module to see if the lazy loading was causing an issue but no luck.

import { NgModule } from ‘@angular/core’;
import { IonicPageModule } from ‘ionic-angular’;
import { FeedbackPage } from ‘./feedback’;
import { FeedbackProvider } from ‘@providers/feedback/feedback’;

@NgModule({
declarations: [
FeedbackPage,
],
imports: [
IonicPageModule.forChild(FeedbackPage),
],
providers: [
FeedbackProvider
]
})
export class FeedbackPageModule {}

I
I then import the provider in the page:

// Providers
import { FeedbackProvider } from ‘@providers/feedback/feedback’;
import { LogProvider } from ‘@providers/log/log’;

@IonicPage()
@Component({
selector: ‘page-feedback’,
templateUrl: ‘feedback.html’,
})
export class FeedbackPage {

sendFeedback(){
   this.feedbackProvider.postFeedback(this.feedback.controls.name.value, this.feedback.controls.contactInfo.value, this.feedback.controls.message.value);
}

}

All this results in my provider logging that it’s constructor is called twice and I’m getting duplicate API calls to my Feedback POST endpoint.

Any thoughts? Thanks.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>