Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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 为什么我的项目会导致;此元素上匹配了多个组件。”;错误?_Angular_Stackblitz - Fatal编程技术网

Angular 为什么我的项目会导致;此元素上匹配了多个组件。”;错误?

Angular 为什么我的项目会导致;此元素上匹配了多个组件。”;错误?,angular,stackblitz,Angular,Stackblitz,我在StackBlitz有以下项目: 我得到这个错误: Template parse errors: More than one component matched on this element. Make sure that only one component's selector can match a given element. 我用谷歌搜索了我的小心脏,但似乎找不到解决办法 这个错误意味着什么?我如何修复它 我应该注意,错误只发生在StackBlitz中,而不发生在我的本地机器

我在StackBlitz有以下项目:

我得到这个错误:

Template parse errors:
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
我用谷歌搜索了我的小心脏,但似乎找不到解决办法

这个错误意味着什么?我如何修复它


我应该注意,错误只发生在StackBlitz中,而不发生在我的本地机器上。

在Angular中,我们不能在同一个元素上有两个组件


错误说明Angular编译器找到了两个匹配
的组件,以防其他人在测试中遇到这种情况,我在同一测试中意外地用两种不同的方式模拟了同一组件。两个模拟都有一个选择器。关于冲突的起因,测试失败输出不清楚。我花了很多时间翻阅这本书,试图找出答案。希望这能为其他人节省一两个小时:|

@NgModule({
  imports: [
    ...
    MatFormFieldModule,
    MatInputModule
  ],
  ...
})
export class InputControlsModule {}
import { ...MatInputModule} from '@angular/material';
                                        |
                                material.umd.js

import { MatFormFieldModule } from '@angular/material/form-field';
                                                  |
                                         material-form-field.umd.js
import {
  ...
  MatInputModule,
  MatFormFieldModule 
} from '@angular/material';