为 angular 添加 angular material 时出错 6

Error adding angular material for angular 6

我真的是angular的新手,我正在学习angular 6 但我无法添加入门页面 via

中所说的组件
ng add component heroes

发生错误,错误是:

Schematic input does not validate against the Schema: {"dryRun":false,"inlineStyle":false,"
inlineTemplate":false,"changeDetection":"Default","styleext":"css","spec":true,"flat":false
,"skipImport":false,"export":false}
Errors:

  Data path "" should NOT have additional properties(dryRun).

当我用谷歌搜索时,有人说可以通过添加 angular material 来修复它,所以我开始安装 angular material,但是我的应用程序错误 这是控制台日志:

compiler.js:215 Uncaught Error: Template parse errors:
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("
    class="sidenav"
    fixedInViewport="true"
    [ERROR ->][attr.role]="isHandset$ | async ? 'dialog' : 'navigation'"
    [mode]="isHandset$ | async ? 'over' : "): ng:///AppModule/MyMenuComponent.html@5:4
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("
    fixedInViewport="true"
    [attr.role]="isHandset$ | async ? 'dialog' : 'navigation'"
    [ERROR ->][mode]="isHandset$ | async ? 'over' : 'side'"
    [opened]="!(isHandset$ | async)">
    <mat-toolbar "): ng:///AppModule/MyMenuComponent.html@6:4
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("
    fixedInViewport="true"
    [attr.role]="isHandset$ | async ? 'dialog' : 'navigation'"
    [ERROR ->][mode]="isHandset$ | async ? 'over' : 'side'"
    [opened]="!(isHandset$ | async)">
    <mat-toolbar "): ng:///AppModule/MyMenuComponent.html@6:4
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("isHandset$ | async ? 'dialog' : 'navigation'"
    [mode]="isHandset$ | async ? 'over' : 'side'"
    [ERROR ->][opened]="!(isHandset$ | async)">
    <mat-toolbar color="primary">Menu</mat-toolbar>
    <mat-nav-li"): ng:///AppModule/MyMenuComponent.html@7:4
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("isHandset$ | async ? 'dialog' : 'navigation'"
    [mode]="isHandset$ | async ? 'over' : 'side'"
    [ERROR ->][opened]="!(isHandset$ | async)">
    <mat-toolbar color="primary">Menu</mat-toolbar>
    <mat-nav-li"): ng:///AppModule/MyMenuComponent.html@7:4
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'dialog' : 'navigation'] in ng:///AppModule/MyMenuComponent.html@5:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
    #drawer
    class="sidenav"
"): ng:///AppModule/MyMenuComponent.html@1:2, Directive MatSidenav
Parser Error: Unexpected token '?' at column 20 in [isHandset$ | async ? 'over' : 'side'] in ng:///AppModule/MyMenuComponent.html@6:4 ("<mat-sidenav-container class="sidenav-container">
  [ERROR ->]<mat-sidenav
   compiler.js:215)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22696)
    at compiler.js:22639
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639)
    at compiler.js:22549
    at Object.then (compiler.js:206)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)
syntaxError @ compiler.js:215
push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse @ compiler.js:14702
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate @ compiler.js:22709
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate @ compiler.js:22696
(anonymous) @ compiler.js:22639
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents @ compiler.js:22639
(anonymous) @ compiler.js:22549
then @ compiler.js:206
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents @ compiler.js:22548
push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync @ compiler.js:22508
push../node_modules/@angular/platform-browser-dynamic/fesm5/platform-browser-dynamic.js.CompilerImpl.compileModuleAsync @ platform-browser-dynamic.js:143
push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule @ core.js:4790
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:81
0 @ main.ts:12
__webpack_require__ @ bootstrap:81
checkDeferredModules @ bootstrap:43
webpackJsonpCallback @ bootstrap:30
(anonymous) @ main.js:1
contentScript.js:86 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
getIp @ contentScript.js:86
countData @ contentScript.js:91
(anonymous) @ contentScript.js:188

请大家帮帮我

您似乎在尝试生成一个新组件, 使用添加,您可以将库添加到您的依赖项-(package.json)。 尝试
"ng generate component [component name]" (https://github.com/angular/angular-cli/wiki/generate-component).

你安装了angular/cli吗? 要使用 ng 生成组件,您需要 angular/cli。 https://cli.angular.io/

无论如何你都可以观看这个 "Angular Material Introduction & Setup" 视频 https://www.youtube.com/watch?v=u679SQsfRVM

你用错了,但首先如果你只是用 angular 学习,没有必要使用 angular material 这个想法是误导。

吴加

Another new CLI command ng add <package> makes adding new capabilities to your project easy. ng add will use your package manager to download new dependencies and invoke an installation script (implemented as a schematic) which can update your project with configuration changes, add additional dependencies (e.g. polyfills), or scaffold package-specific initialization code.

ng add命令只用于依赖管理,勾选this

如果您尝试生成组件,请遵循以下步骤:

ng generate component my-new-component
ng g component my-new-component # using the alias

在潜水前学习 angular-cli 的基础知识,或者至少完成 angular.io.

中的 tour-of-heroes 教程

要从文档中获得完整的 angular-cli 命令用法,here

Data path "" should NOT have additional properties(dryRun).

此错误不是 material 错误。

这意味着在您的 angular.json 文件中您将 "dryRun" 作为 属性,这是不受支持的。看样子是
"dryRun" 属性 允许您在不实际编辑文件的情况下查看执行 ng g 时会发生什么。

例如:ng g c ops-components/dividers --project ops-lib --dryRun

删除 dryRun 属性.