Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度4-在防护罩中使用部件维修_Angular_Angular2 Modules_Angular2 Guards - Fatal编程技术网

Angular 角度4-在防护罩中使用部件维修

Angular 角度4-在防护罩中使用部件维修,angular,angular2-modules,angular2-guards,Angular,Angular2 Modules,Angular2 Guards,我有一个延迟加载的模块,带有根和子组件。我还提供了一个服务,用于在根和子组件以及同级之间共享数据 背后的用例是一个向导,用户可以在其中通过多个步骤设置一些数据。每个步骤的数据都全局存储在服务中,以便父组件和每个子组件都能够访问整个数据 现在我想为单个步骤创建防护,它应该检查之前的步骤是否已完成(服务中的数据已设置),以防止用户在不执行之前的步骤的情况下通过URL访问进一步的步骤 模块 @NgModule({ imports: [ CommonModule, FormsModule

我有一个延迟加载的模块,带有根和子组件。我还提供了一个服务,用于在根和子组件以及同级之间共享数据

背后的用例是一个向导,用户可以在其中通过多个步骤设置一些数据。每个步骤的数据都全局存储在服务中,以便父组件和每个子组件都能够访问整个数据

现在我想为单个步骤创建防护,它应该检查之前的步骤是否已完成(服务中的数据已设置),以防止用户在不执行之前的步骤的情况下通过URL访问进一步的步骤

模块

@NgModule({
imports: [
    CommonModule,
    FormsModule,
    AppointmentAgreementRouting
],
declarations: [
    AppointmentAgreementComponent,
    TopicSectionComponent,
    BranchSectionComponent,
    DatetimeSectionComponent,
    PersonalDataSectionComponent,
    ConfirmationSectionComponent,
    SectionDirective
],
providers: [
    CanActivateBranch, <-- Guard which should check if the data is set in service
    { provide: 'components', useValue: [AppointmentAgreementComponent], multi: true }
],
entryComponents: [
    AppointmentAgreementComponent,
    TopicSectionComponent,
    BranchSectionComponent,
    DatetimeSectionComponent,
    PersonalDataSectionComponent,
    ConfirmationSectionComponent
]
})
根分量

@Component({
selector: 'appointment-agreement',
templateUrl: './appointmentAgreement.component.html',
providers: [
    AppointmentAgreementCommunicationService <-- Service to share data
]
})
@组件({
选择器:'任命协议',
templateUrl:“./AppointAgreement.component.html”,
供应商:[

AppointmentAgreementCommunicationService为什么要在组件中提供服务?是否有任何特定的用例。否则,如果您在模块中提供数据共享服务,则此问题将得到解决。您是否可以从根组件中删除服务,然后只在模块中提供服务?所有这些entryComponents的用途是什么?From文档:
Angular自动将以下类型的组件添加到模块的entryComponents中:(1)@NgModule.bootstrap列表中的组件。(2)路由器配置中引用的组件。
因此,由于这些组件是路由的一部分,因此
入口组件中也不需要这些组件。
请参阅此链接:我的问题非常好。我面临同样的问题。如果您发现了什么,请告诉我们。此外,警卫使用的服务与路由器相同,这一点很重要“组件共享”一个,因为服务可以是有状态的。
@Component({
selector: 'appointment-agreement',
templateUrl: './appointmentAgreement.component.html',
providers: [
    AppointmentAgreementCommunicationService <-- Service to share data
]
})