我们如何在 Angular 17 中使用 Angular Material UI

问题描述 投票:0回答:1

如果没有 app.module.ts 文件,那么我们如何使用 Angular Material ,因为要使用 Angular Material 首先我们需要导入材质模块,还有其他方法吗?

我尝试将其导入配置文件中,但现在可以了

angular-material
1个回答
0
投票

基本上,Angular v-17 以后的版本默认通过 CLI 独立运行,这意味着当您创建新项目时,它不会包含任何模块。您可以使用 --no-standalone 标志创建一个项目,即新项目 --no-standalone,或者您可以将依赖项导入到组件而不是 app.modules 中,如下面的代码:

import { MatAutocompleteModule } from '@angular/material/autocomplete';
@Component({
  standalone:true,
  imports: [
     MatAutocompleteModule,
   ],
   selector: 'your-component',
   templateUrl: './your.component.html',
   styleUrls: ['./your.component.scss']
 })

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.