无法绑定到“ dividerColor”,因为它不是“ mat-form-field”的已知属性

时间:2019-11-15 07:46:04

标签: angular npm localhost mat-form-field

我创建了一个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学习者,不知道此模块是否已被弃用,以及如何用新模块替换它?

2 个答案:

答案 0 :(得分:1)

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

Error in template DishDetailComponent.html@75:9

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

答案 1 :(得分:0)

我在这里找到了一个更改日志:https://www.reddit.com/r/Angular2/comments/86ta8k/angular_material_600beta5_changelog/,并在项目中用dividerColor替换了所有color,并且一切正常!

感谢@Fel的帮助。