【问题标题】:Can't bind to 'dividerColor' since it isn't a known property of 'mat-form-field'无法绑定到“dividerColor”,因为它不是“mat-form-field”的已知属性
【发布时间】:2020-03-11 08:02:45
【问题描述】:

我创建了一个 Angular 应用并成功编译:

 10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.html

chunk {main} main.js, main.js.map (main) 163 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 399 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.09 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 186 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.95 MB [initial] [rendered]
Date: 2019-11-15T07:04:24.466Z - Hash: 14ff089b7b0356766301 - Time: 16736ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.

但是当我转到http://localhost:4200 时,我在浏览器选项卡中只看到应用程序的名称和徽标,但在内容位置看到一个空白页面。我可以在此地址上运行其他应用程序,但这个新应用程序不起作用并显示任何内容。

您可以在这里找到项目文件:https://github.com/rajishpajish/test

编辑:我检查了开发者控制台作为建议的答案,发现了这个错误消息:

Uncaught Error: Template parse errors:
Can't bind to 'dividerColor' since it isn't a known property of 'mat-form-field'.
1. If 'mat-form-field' is an Angular component and it has 'dividerColor' input, then verify that it is part of this module.
2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
      <p>
        <mat-form-field class="full-width"
         [ERROR ->]dividerColor="{{(formErrors.author) ? 'warn' : 'primary'}}">
          <input matInput formControlNa"): ng:///AppModule/DishDetailComponent.html@62:9
Can't bind to 'dividerColor' since it isn't a known property of 'mat-form-field'.
1. If 'mat-form-field' is an Angular component and it has 'dividerColor' input, then verify that it is part of this module.
2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
      <p>
        <mat-form-field class="full-width"
         [ERROR ->]dividerColor="{{(formErrors.comment) ? 'warn' : 'primary'}}">
          <textarea matInput formContr"): ng:///AppModule/DishDetailComponent.html@75:9
    at syntaxError (compiler.js:2175)
    at TemplateParser.parse (compiler.js:11188)
    at JitCompiler._parseTemplate (compiler.js:25721)
    at JitCompiler._compileTemplate (compiler.js:25709)
    at compiler.js:25653
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (compiler.js:25653)
    at compiler.js:25566
    at Object.then (compiler.js:2166)
    at JitCompiler._compileModuleAndComponents (compiler.js:25565)

由于我是一个新的 Angular 学习者,不知道这个模块是否已被弃用以及如何用新模块替换它?

【问题讨论】:

  • 检查控制台,你可能有一些错误。

标签: angular npm localhost mat-form-field


【解决方案1】:

如果您打开开发者控制台,您会看到其中一个模板存在错误 (DishDetailComponent.html@75:9):

如您所见,它抱怨dividerColor 组件中没有dividerColor 属性。也许它是一个已弃用的属性,因为我在它的 API 中看不到它:https://material.angular.io/components/form-field/api

【讨论】:

    【解决方案2】:

    我在这里找到了一个更改日志:https://www.reddit.com/r/Angular2/comments/86ta8k/angular_material_600beta5_changelog/ 并在我的项目中将所有 dividerColors 替换为 color 并且它有效!

    感谢@Fel 的帮助。

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 2019-09-19
      • 2019-11-10
      • 2017-09-01
      • 2017-02-26
      • 2018-07-21
      • 2019-04-10
      相关资源
      最近更新 更多