gpt4 book ai didi

Angular 2 提供的参数与调用目标(spec.ts)的任何签名都不匹配

转载 作者:太空狗 更新时间:2023-10-29 17:59:51 24 4
gpt4 key购买 nike

我正在使用 Angular2 Cli 构建 Angular2 应用程序。我有一个 notifications.component,它有一个像这样的构造函数

constructor(private _elRef: ElementRef) {}

当我构建 (npm start) 时出现此错误

...angular2/tmp/broccoli_type_script_compiler-input_base_path-wKrIZXNv.tmp/0/src/app/notifications/notifications.component.spec.ts (10, 21): Supplied parameters do not match any signature of call target

angular cli生成的文件notifications.component.spec.ts是这样的

import { By }           from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { addProviders, async, inject } from '@angular/core/testing';
import { NotificationsComponent } from './notifications.component';

describe('Component: Notifications', () => {
it('should create an instance', () => {
let component = new NotificationsComponent();
expect(component).toBeTruthy();
});
});

但是,如果我在没有构造函数参数的情况下进行构建,则一切正常。如果我在构建后添加此参数,一切都会正常进行。

我错过了什么?

最佳答案

看这行 let component = new NotificationsComponent();

当您为 NotificationsComponent 创建一个新对象时,您没有提供参数,而它的构造函数需要一个类型为 ElementRef 的对象。

这就是为什么您在没有构造函数参数的情况下构建一切正常的原因。

关于Angular 2 提供的参数与调用目标(spec.ts)的任何签名都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38579151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com