0
votes

I have two components both using the same Service I created

   #Component A
        @Component({
  templateUrl:          'build/pages/templateReunionCourse/templateReunionCourse.html',
  providers: [
    ReunionService,JSONP_PROVIDERS
  ]
})
export class Reunion{
    month: any;
     constructor(private loadingController: LoadingController,private navCtrl: NavController, public reunionService: ReunionService, public cmpB: ComponentB) 
  {

     this.month = new Date().toDateString();  

  } 
    onClickItem(string: any){
        this.cmpB.data=string;
    this.navCtrl.setRoot(Courses);

}
}

#ComponnetB @Component({ templateUrl: 'build/pages/courses/courses.html', providers: [ReunionService] }) export class Courses { Date: any; data: any; constructor(private loadingController: LoadingController, private navCtrl: NavController, public courseService: ReunionService) { this.Date = new Date().toDateString(); this.presentLoading(); this.loadRaces();

  }
}

When I attempt to Run. I get the error No provider for Component A

Any insight or alternative approach would b appreciated. My goal is to set data in component B from Component A so that when I push component B to Front I can view that data

1
Can you just use static parameters and functions? The provider problem is a bootstrapping issue to the appmisha130
how do I declare a static parameter. I am new to Ionic and angular JSuser2955481
public static param:string; and you can access directly like classname.param = 'foo';misha130
Doesnt seem like best practice but it works fine. Thanks Mishauser2955481
You are right it isn't, but its simple and cheap performance wise. I am sure you'll figure out later how it can be done with providersmisha130

1 Answers

0
votes

Well I am back took me a while but I solved the Issue with what I think is better practice. I created a view-less Component. created the variable I wanted to aces So this current view-less component acts like a bus(bridge) between the Components. then Ionic bootstrap them in my parent Component while Injecting in the Child. it stores the state of the resources . If code help is needed by anyone on that just ping