Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 错误:失败:模板分析错误:';mat复选框';不是已知元素_Angular_Typescript_Testing_Angular Material - Fatal编程技术网

Angular 错误:失败:模板分析错误:';mat复选框';不是已知元素

Angular 错误:失败:模板分析错误:';mat复选框';不是已知元素,angular,typescript,testing,angular-material,Angular,Typescript,Testing,Angular Material,我创建此代码用于测试我的组件 我尝试了以下代码: describe('Component: AddAlarms', () => { let component: AddAlarmsFormComponent; let fixture: ComponentFixture<AddAlarmsFormComponent>; beforeEach(() => { TestBed.configureTestingModule({

我创建此代码用于测试我的组件

我尝试了以下代码:

describe('Component: AddAlarms', () => {
    let component: AddAlarmsFormComponent;
    let fixture: ComponentFixture<AddAlarmsFormComponent>;
    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [AddAlarmsFormComponent]
        });
        fixture = TestBed.createComponent(AddAlarmsFormComponent);
        component = fixture.componentInstance;
    });
});
我验证了我的module.ts,一切正常。所以,我有这个:

import {MatCheckboxModule} from '@angular/material/checkbox';
你能告诉我有什么问题吗?

太好了

但是我认为您需要在
spec.ts
中导入
MatCheckboxModule
,或者您忘记在
ngModule
上的
中导入模块


你能告诉我是否有效吗?

你需要在
声明上面添加
导入
数组,如下所示:

import { MatCheckboxModule } from '@angular/material/checkbox';
TestBed.configureTestingModule({
   imports: [
        MatCheckboxModule
   ],
   declarations: [AddAlarmsFormComponent]
})
添加如下内容:

import { MatCheckboxModule } from '@angular/material/checkbox';
TestBed.configureTestingModule({
   imports: [
        MatCheckboxModule
   ],
   declarations: [AddAlarmsFormComponent]
})
然后像这样添加
导入
数组:

import { MatCheckboxModule } from '@angular/material/checkbox';
TestBed.configureTestingModule({
   imports: [
        MatCheckboxModule
   ],
   declarations: [AddAlarmsFormComponent]
})

我在这两个问题上都做出了决定,即使在<代码>模块<代码>和<代码> SPEC.TS /CODE >中,但是没有任何角度的示例代码甚至没有这个,他们的文档确实是低级的。