- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Angular CLI 1.0.0-beta.32.2 并正在为 Angular 2 服务编写单元测试,该服务动态创建一个组件并将其插入另一个组件。
在我的单元测试中,我尝试创建一个模拟组件来测试我的服务,但是 ng test
的输出抛出错误,指出我的模拟组件在 entryComponents
中指定属性(property)。当我尝试将组件添加到 entryComponents
中时TestModuleMetadata 对象的属性,如下所示:TestBed.createTestingModule({...entryComponents: [ TestDialogComponent ]...})
我看到以下错误说明 entryComponents
属性不存在。
Chrome 56.0.2924 (Windows 10 0.0.0) DialogService should create a child component when opening FAILED
Error: No component factory found for TestDialogComponent. Did you add it to @NgModule.entryComponents?
查看 TestModuleMetadata 定义表明 entryComponents 属性不存在。那么我该如何在 Angular 2 和 Jasmine 的单元测试中动态创建组件呢?
最佳答案
据我所知还没有支持。作为解决方法,您可以使用 entryComponent
创建假模块并将其导入您的测试模块
@NgModule({
imports: [CommonModule],
declarations: [TestDialogComponent],
entryComponents: [TestDialogComponent]
})
export class FakeTestDialogModule {}
然后
TestBed.configureTestingModule({
imports: [FakeTestDialogModule]
关于unit-testing - Angular 2 TestModuleMetadata 没有 EntryComponents 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42398059/
我正在使用 Angular Cli 创建组件。 我正在使用这个命令: ng g c DeviceComponent --module=./views/administration/Accounting
我想从组件加载模态。在 Angular Material 文档中,编写了在 entryComponents 中添加模态组件: 这个: @NgModule({ imports: [ Comm
我正在使用 Angular 8,我想在我的项目中延迟加载对话框。执行此操作时出现以下错误:- No component factory found for EditProfileComponent.
import {Component} from '@angular/core'; import {IonicPage, NavController, NavParams} from 'ionic-an
我有一个代码: ////////////////login.module.ts import { NgModule } from '@angular/core'; import { IonicPage
我有 ngx-bootstrap 模态组件。此模式在 shared 文件夹中使用。我在我的 DashboardModule 中使用这个 FirstModalComponent,例如: // Dashb
您好,我是 angular2 和 typescript 的新手。我正在动态加载组件,我想知道是否有一种方法可以使用模块的“声明”和“entryComponents”中的服务来声明我的组件。 使用 ty
例如,假设您有以下组件: import { Another } from "./Another"; @Component({ entryComponents: [ Anothe
这里我有一个方法“confirmSth”,动态加载了一个组件“SnackCheckBoxComponent”。 我想知道我是否可以在我的 OrderDetailComponent 中获取一些消息来区分
我有以下一段 Angular 代码: dashboard.component.ts import {Component, AfterViewInit, ComponentFactoryResolver
我的 app.module.ts 中有这个: import { BrowserModule } from '@angular/platform-browser'; import { ErrorHand
我有一个组件,它接收组件的组件类以动态创建为子组件。 let componentFactory = this.componentFactoryResolver.resolveComponentFact
我在 Angular 6 中使用 ng-bootstrap 模态时遇到问题。 首先,我有 2 个模块: AppModule 和 ComponentModule 这是ComponentModule: @
我在 Angular 6 中使用 ng-bootstrap 模态时遇到问题。 首先,我有 2 个模块: AppModule 和 ComponentModule 这是ComponentModule: @
我制作了一个弹出组件,它可以动态加载内容组件,而不管类型如何。在 RC4 之后,如果不将组件添加到 entryComponents 列表中是不可能注入(inject)组件的。 是否可以加载组件而不在
当我创建一个新的页面组件时,我现在必须将它放在声明和 entryComponents 数组中。为什么它必须在两个地方? 例如,我刚刚创建了一个新的 login.page.ts 文件,但我必须在声明和
在将 ag-grid 与 angular4 一起使用时,我遇到了以下错误消息。 我试图在通过 HTTP 获取 json 后显示行数据。 this.gridOptions.api.setRowData(
我正在尝试关注 https://material.angular.io/components/component/dialog 上的文档但我不明白为什么会出现以下问题? 我在组件中添加了以下内容: @
我正在开发一个依赖于 angular 2 的 Ionic 应用程序 ( 2.0.0-rc0 )。所以引入了新的ngModules。我正在下面添加我的 app.module.ts.。 import {
谁能清楚地解释为什么在 IVY 编译器中,入口组件 API 不再需要了?换句话说,发生了什么变化内部 所以Angular突然不需要提醒你要动态创建组件 最佳答案 View 引擎 在 Ivy 之前, V
我是一名优秀的程序员,十分优秀!