19

我正在尝试使用此页面上显示的 Angular 架构。 当我尝试在项目根目录的终端中使用以下命令ng generate @angular/material:material-nav --name name-of-new-nav时,出现以下红色错误,

无法解析集合“@angular/material”。错误:无法解析集合“@angular/material”。在 NodeModulesEngineHost._resolveCollectionPath (/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:88:15) 在 NodeModulesEngineHost。 createCollectionDescription (/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:106:27) 在 SchematicEngine._createCollectionDescription (/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular-devkit/schematics/src/engine/engine.js:78:40)在 SchematicEngine。在 Object.getCollection (/Users/jeremypeters/ MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/utilities/schematics.js:28:31) 在 GenerateCommand.getOptions (/Users/jeremypeters/MEGA/development/learning/angular/material-learn /node_modules/@angular/cli/models/schematic-command.js:193:41) 在 GenerateCommand。(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:38:53) 在 Generator.next () 在 /Users/jeremypeters/MEGA/development /learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:7:71 at new Promise () 在 GenerateCommand.getOptions (/Users/jeremypeters/MEGA/development/学习/角度/材料学习/node_modules/@angular/cli/models/schematic-command.js:193:41)在 GenerateCommand。(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:38:53) 在 Generator.next () 在 /Users/jeremypeters/MEGA/development /learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:7:71 at new Promise () 在 GenerateCommand.getOptions (/Users/jeremypeters/MEGA/development/学习/角度/材料学习/node_modules/@angular/cli/models/schematic-command.js:193:41)在 GenerateCommand。(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:38:53) 在 Generator.next () 在 /Users/jeremypeters/MEGA/development /learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:7:71 at new Promise () 41) 在生成命令处。(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:38:53) 在 Generator.next () 在 /Users/jeremypeters/MEGA/development /learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:7:71 at new Promise () 41) 在生成命令处。(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:38:53) 在 Generator.next () 在 /Users/jeremypeters/MEGA/development /learning/angular/material-learn/node_modules/@angular/cli/commands/generate.js:7:71 at new Promise ()

我怎样才能让它工作?

信息:Angular CLI:6.0.8

4

6 回答 6

40

好像坏了,临时解决,用下面的版本

ng add @angular/material@6.2.1
于 2018-06-23T19:18:01.177 回答
8

您可以使用以下方式安装它:
ng generate @angular/material:dashboard --name myDashboard

对于其他组件,它将是:
ng generate @angular/material:nav --name myNav
ng generate @angular/material:table --name myTable

您可以在文件中找到有关其他组件原理图的信息,该文件位于:
/node_modules/@angular/material/schematics/collection.json

于 2018-07-20T11:04:50.317 回答
3

尝试以下 cmds,它对我有用:

npm install --save @angular/material@6.2.1 @angular/cdk@6.2.1

ng add @angular/material@6.2.1
于 2018-06-26T13:24:48.303 回答
1

以这种方式为我工作(来自文档

ng add @angular/material

ng generate @angular/material:material-nav --name <component-name>

ng generate @angular/material:material-dashboard --name <component-name>

ng generate @angular/material:material-table --name <component-name>

角 6.4.7

于 2018-10-11T10:05:41.707 回答
0

错误是由于 Angular Material 7 造成的。只需在终端中运行以下命令 ng add @angular/material@6.2.1

于 2018-11-16T14:35:08.290 回答
0

我发现你的语法错误:ng generate @angular/material:nav <name-of-new-nav>

于 2019-09-19T09:13:25.003 回答