angular - 将数据从组件传递到 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();
}
解决方案
推荐阅读
- c++ - 为什么在 C++ 中合并两个已排序的链表时总是出现此错误?
- php - 如何为特定运输方式禁用多个支付网关
- c++ - gtk_grid_new(); 在编译时导致未定义的引用错误
- react-admin - 在 React-admin 中以编程方式重定向或构建 URL
- php - 添加后不显示 Prestashop 1.7 图像
- reactjs - ReactJS 在我设置状态时类渲染两次是否正常
- c++ - 如何检测 VS C++ 编译器是否支持 C++11?
- powershell - Azure DevOps Task ScriptArguments # ScriptArguments 中的注释问题
- c - 多维数组寻址 C
- angular-material - 如何使用 chart.js 显示分组条形图?