小编Ann*_*a N的帖子

使用Angular 2路由器在Ionic 2应用程序中有意义吗?

我们已经尝试将我们的Angular 2应用程序(由我们的朋友编写,因此我们可能不知道所有细节)移动到Ionic 2.然而,我们还没有设法让它工作,因此下面的问题.

  1. Angular 2路由器在Ionic 2中工作吗?
  2. 在Ionic 2应用程序中使用Angular 2路由器是否有意义,还是应该直接选择DeepLinker

编辑:我不确定目前的状态是什么,但我在这里读到:

«Angular路由器目前正在进行大量开发和重构.因此,Angular的路由器目前在Ionic中被禁用.»

  1. 代码/ metadata/build-script/package.json中的哪个位置是激活路由器的入口点?我们在NgModule中有路由,但是当我们访问应用程序的主URL或子URL时,它似乎没有动作:

    @NgModule({
      declarations: [
        AppComponent,
        TestComponent,
        AgendasListComponent,
        TasksListComponent,
        SnackBarComponent,
        ConfirmationDialog,
        AgendaComponent,
        LoginComponent
      ],
      entryComponents: [
        ConfirmationDialog
      ],
      imports: [
        BrowserModule,
        HttpModule,
        MaterialModule.forRoot(),
        AngularFireModule.initializeApp(firebaseConfig, firebaseAuthConfig),
        RouterModule.forRoot([
        {
          path: '',
          redirectTo: 'agendas',
          pathMatch: 'full',
          canActivate:[ RouterGuardService ]
        },           
        {
          path: 'agendas',
          component: AgendasListComponent,
          canActivate:[ RouterGuardService ]           
        }
        ...
    
    Run Code Online (Sandbox Code Playgroud)

typescript ionic2 angular2-routing ng-modules angular

8
推荐指数
2
解决办法
4648
查看次数

覆盖Angular TestBed中另一个模块中的组件

我正在编写TestBed单元测试。

有一个特定的组件,它是被测组件的子组件。测试运行时,该子组件会导致错误。该子组件与测试本身无关;这只是造成问题。

我想用一个假人替换它,或防止它被添加。

有问题的组件来自被测组件以外的其他模块。

我试图做一个存根/虚拟:

@Component({
  selector : 'problematic-component-selector',
  template  : 'FAKE CAPTCHA',
})
export class ProblematicComponentStubComponent {

}
Run Code Online (Sandbox Code Playgroud)

这是我的beforeEach

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [
      ReactiveFormsModule,
      FormsModule,
      RouterModule,
      ModuleOfProblematicComponent,
    ],
    declarations: [
      ComponentUnderTest,
      ProblematicComponentStubComponent, /* NOTE: here I tried to declare the fake one */
    ],
    providers: [
      { provide: Router, useClass: RouterStub },
      { provide: ActivatedRoute, useClass: Stub },
    ],
Run Code Online (Sandbox Code Playgroud)

我尝试覆盖组件模板,以防止出现以下错误:

TestBed.overrideComponent(ProblematicComponent, {
  set: {
    template: 'Fake Captcha' // prevent ReCaptcha error
  }
}) …
Run Code Online (Sandbox Code Playgroud)

unit-testing testbed karma-jasmine angular

3
推荐指数
1
解决办法
2518
查看次数