首页 文章

从组件b访问组件a并设置其属性

提问于
浏览
0

我有两个组件都使用我创建的相同服务

#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;数据:任何;构造函数(private loadingController:LoadingController,private navCtrl:NavController,public courseService:ReunionService){this.Date = new Date() . toDateString(); this.presentLoading(); this.loadRaces();

}
}

当我尝试跑步时 . 我得到组件A的错误没有提供者

任何见解或替代方法都会受到赞赏 . 我的目标是从组件A中设置组件B中的数据,这样当我将组件B推送到前面时,我可以查看该数据

1 回答

  • 0

    好吧,我回来了我一段时间,但我用我认为更好的做法解决了问题 . 我创建了一个无视图组件 . 创建了我想要的变量所以这个当前的无视图组件就像组件之间的总线(桥) . 然后Ionic在我的父组件中引导它们,同时在Child中注入 . 它存储资源的状态 . 如果只是ping那个人需要代码帮助

相关问题