首页 > 解决方案 > 将数据从组件传递到 Angular 2 中的模块

问题描述

我需要将数据从一个组件传递到它的模块。我需要组件中的数据才能在模块中使用它。我有一个 tab1.component.ts 有一个 tab.module.ts。在 tab.module.ts 我有一个需要设置的配置,其值来自 tab1.component.ts,如下所示:

tab1.module.ts

export function createConfig(): SignalRConfiguration {
  const config = new SignalRConfiguration();
  config.hubName = 'ServerHub';
  config.qs = { user: 'Lane' };
  config.url = ???';  <==== I NEED THE DATA HERE. IT SHOULD COME FROM THE COMPONENT
  config.executeEventsInZone = true;
  config.executeErrorsInZone = false;
  config.executeStatusChangeInZone = true;
  return config;
}

@NgModule({
  imports: [
    IonicModule,
    CommonModule,
    SignalRModule.forRoot(createConfig),
    FormsModule,
    RouterModule.forChild([{ path: '', component: Tab1Page }])
  ],
  declarations: [Tab1Page]
})
export class Tab1PageModule {}

tab1.component.ts

onSubmit(form: NgForm){
    if(!form.valid) {
      return;
    }
    this.ipAddress = form.value;
    console.log(this.ipAddress); <=== I NEED THIS IN THE MODULE ABOVE
    this.cs.startConnection();
  }

标签: angulartypescript

解决方案


推荐阅读