AngularCLI和Angular材质(示意图)错误:无法解决集合“ @ angular / material”

时间:2018-06-23 18:24:40

标签: angular angular-material angular-cli-v6

我正在尝试使用this page.上显示的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-host.js:88:15)       在NodeModulesEngineHost.createCollectionDescription(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular-devkit/schematics/tools/file-system-engine-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.createCollection(/Users/jeremypeters/MEGA/development/learning/angular/material-learn/node_modules/@angular-devkit/schematics/src/engine/engine.js:71:43)       在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       在新的Promise()

如何使它工作?

信息:Angular CLI:6.0.8

6 个答案:

答案 0 :(得分:34)

似乎坏了, 临时解决方案,请使用以下版本

ng add @angular/material@6.2.1

答案 1 :(得分:7)

您可以使用以下软件进行安装:
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

答案 2 :(得分:3)

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

['AFC Bournemouth', 0, 0
 'Arsenal', 4, 4
 'Brighton & Hove Albion', 0, 0
 'Burnley', 0, 0
 'Chelsea', 0, 0
 'Crystal Palace', 0, 0
 'Everton', 0, 0
 'Huddersfield Town', 0, 3
 'Leicester City', 3, 3
 'Liverpool', 0, 0
 'Manchester City', 0, 0
 'Manchester United', 0, 0
 'Newcastle United', 0, 0
 'Southampton', 0, 0
 'Stoke City', 0, 0
 'Swansea City', 0, 0
 'Tottenham Hotspur', 0, 0
 'Watford', 0, 0
 'West Bromwich Albion', 0, 0
 'West Ham United'] , 0, 0

答案 3 :(得分:0)

以这种方式为我工作(from docs

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

答案 4 :(得分:0)

该错误归因于Angular Material7。只需在终端中运行以下命令 ng添加@ angular / material @ 6.2.1

答案 5 :(得分:0)

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