Angular 2提供的参数与调用目标的任何签名都不匹配(spec.ts)
发布时间:2020-12-17 17:07:23 所属栏目:安全 来源:网络整理
导读:我正在使用Angular2 Cli构建Angular2 App. 我有一个notifications.component,它有一个像这样的构造函数 constructor(private _elRef: ElementRef) {} 当我构建(npm start)时,我收到此错误 ...angular2/tmp/broccoli_type_script_compiler-input_base_path-wK
我正在使用Angular2 Cli构建Angular2 App.
我有一个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(); }); }); 但是,如果我在没有构造函数参数的情况下构建,一切正常.如果我在构建后添加此参数,一切都正常. 我错过了什么? 解决方法
看看这一行让component = new NotificationsComponent();.
在为NotificationsComponent创建新对象时,您没有提供参数,而其构造函数需要ElementRef类型的对象. 这就是为什么你在没有构造函数参数的情况下构建一切正常. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |