小编Mat*_*ler的帖子

无法读取未定义的属性"ngMetadataName"

我正在使用Angular 6和Angular Material.更新到最新版本后,控制台在开发中抛出此错误.在生产上它正在发挥作用

Cannot read property 'ngMetadataName' of undefined

它发生在我试图通过服务打开材料对话框时(没有服务他们工作正常).我认为它与注射剂有关,但我不确定.

版本:cli:6.1.5,核心:6.1.4,材料:6.4.6

这是日志堆栈:

CustomDialogComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'ngMetadataName' of undefined
at injectArgs (core.js:1418)
at core.js:1491
at _callFactory (core.js:8438)
at _createProviderInstance (core.js:8396)
at resolveNgModuleDep (core.js:8371)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9064)
at PortalInjector.push../node_modules/@angular/cdk/esm5/portal.es5.js.PortalInjector.get (portal.es5.js:732)
at resolveDep (core.js:9419)
at createClass (core.js:9309)
at createDirectiveInstance (core.js:9186)
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

服务中的对话框,其中抛出错误:

 @Injectable({
  providedIn: 'root'
})
export class customService {
  constructor(private store: Store<RootState>, private dialog: MatDialog) {}

const dialogRef = this.dialog.open(customDialogComponent, {
  width: '300px',
  data: {
    loading: false, …
Run Code Online (Sandbox Code Playgroud)

angular-cli angular angular6 angular-material-6

17
推荐指数
2
解决办法
1万
查看次数

错误单元测试 Angular 8 / Jasmine / Karma:RangeError:超出最大调用堆栈大小

我正在使用 Jasmine 对我的 Angular 应用程序进行单元测试,有时 Karma 窗口中会出现以下错误。我找不到它可能来自哪里,因为它在重新加载时发生了大约 1/5 次。处于观看模式时会发生这种情况。有什么线索吗?

zone.js:202 Uncaught RangeError: Maximum call stack size exceeded
      at RegExp.exec (<anonymous>)
      at Array.<anonymous> (VM2578 browser-source-map-support.js:110)
      at VM2578 browser-source-map-support.js:102
      at d (VM2578 browser-source-map-support.js:103)
      at q (VM2578 browser-source-map-support.js:106)
      at VM2578 browser-source-map-support.js:107
      at Array.map (<anonymous>)
      at Function.w [as prepareStackTrace] (VM2578 browser-source-map-support.js:107)
      at VM2580 jasmine.js:897
      at onerror (VM2580 jasmine.js:3199)
Run Code Online (Sandbox Code Playgroud)

大多数时候,重新加载一次业力窗口后,测试集再次运行并且可以正常工作。

unit-testing jasmine karma-jasmine angular

8
推荐指数
1
解决办法
2125
查看次数

如何测试 Nestjs 拦截器?

我找不到关于如何在 NestJS 中测试拦截器的任何解释

这个简单的示例拦截了一个 POST 查询,以将一个属性添加到正文中提供的示例模型中。

@Injectable()
export class SubscriberInterceptor implements NestInterceptor {
  async intercept(
    context: ExecutionContext,
    next: CallHandler,
  ): Promise<Observable<ExampleModel>> {
    let body: ExampleModel = context.switchToHttp().getRequest().body;
    body = {
      ...body,
      addedAttribute: 'example',
    };
    context.switchToHttp().getRequest().body = body;
    return next.handle();
  }
}
Run Code Online (Sandbox Code Playgroud)

我想测试拦截函数中发生了什么。

迄今为止:

const interceptor = new SubscriberInterceptor();

describe('SubscriberInterceptor', () => {
  it('should be defined', () => {
    expect(interceptor).toBeDefined();
  });

  describe('#intercept', () => {
    it('should add the addedAttribute to the body', async () => {
      expect(await interceptor.intercept(arg1, arg2)).toBe({ ...bodyMock, addedAttribute: …
Run Code Online (Sandbox Code Playgroud)

unit-testing interceptor typescript jestjs nestjs

4
推荐指数
1
解决办法
4327
查看次数

按最接近的值排序数组

我想找到一个按最近值排序的算法.我想一个例子可以澄清我在说什么:

假设我们有一个这样的数组: var arr = [10,45,69,72,80];var num = 73;

我想要的是一个像这样返回这个数组的函数.

function orderByClosest(arr, num){
  //enter code here
  return arr; //and arr = [72,69,80,45,10]
}
Run Code Online (Sandbox Code Playgroud)

希望我足够清楚.

谢谢.

javascript arrays

2
推荐指数
1
解决办法
130
查看次数