Angular Material:选择列表示例无效
Angular Material: selection list example not working
我正在尝试使用 Angular Material (7.0) 选择列表 as described here。
页面上的示例代码片段是
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes">
{{shoe}}
</mat-list-option>
</mat-selection-list>
<p>
Options selected: {{shoes.selectedOptions.selected.length}}
</p>
使用 TS 文件中定义的 typesOfShoes
,如其代码段中所述:
export class HomeComponent implements OnInit {
typesOfShoes: string[] = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
constructor() {}
ngOnInit() {}
}
对我来说很有意义,但是当我尝试编译时,我得到了 Error:
ERROR in: Can't bind to 'ngForOf' since it isn't a known property of 'mat-list-option'.
1. If 'mat-list-option' is an Angular component and it has 'ngForOf' input,
then verify that it is part of this module.
2. If 'mat-list-option' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA'
to the '@NgModule.schemas' of this component to suppress this message.
etc.
我已经将 MatListModule
导入到我的应用程序模块中。
我看不到与要导入的列表选项相关的其他模块。
我在这里错过了什么?
在 @NgModule()
中导入 BrowserModule
(或 CommonModule
,如果它是子模块):
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule],
})
我正在尝试使用 Angular Material (7.0) 选择列表 as described here。
页面上的示例代码片段是
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes">
{{shoe}}
</mat-list-option>
</mat-selection-list>
<p>
Options selected: {{shoes.selectedOptions.selected.length}}
</p>
使用 TS 文件中定义的 typesOfShoes
,如其代码段中所述:
export class HomeComponent implements OnInit {
typesOfShoes: string[] = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
constructor() {}
ngOnInit() {}
}
对我来说很有意义,但是当我尝试编译时,我得到了 Error:
ERROR in: Can't bind to 'ngForOf' since it isn't a known property of 'mat-list-option'.
1. If 'mat-list-option' is an Angular component and it has 'ngForOf' input,
then verify that it is part of this module.
2. If 'mat-list-option' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA'
to the '@NgModule.schemas' of this component to suppress this message.
etc.
我已经将 MatListModule
导入到我的应用程序模块中。
我看不到与要导入的列表选项相关的其他模块。
我在这里错过了什么?
在 @NgModule()
中导入 BrowserModule
(或 CommonModule
,如果它是子模块):
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
imports: [BrowserModule],
})