[英]Angular 6: mat-toolbar and mat-toolbar-row in footer (shared) component is not displaying properly (but without any error)?
在撰写本文时,我已经阅读了所有类似的问题,但在该列表中找不到解决方案。
我在以下链接中搜索,但找不到解决方案:
Angular Material v6 Mat-Footer-“无法读取未定义的属性'template'”
Angular 6 Mat-Table和Footer,无需页面滚动
Angular 6'mat-button-toggle'不是一个已知元素
'mat-toolbar'不是一个已知元素-Angular 5
如何在md-toolbar中定位md-toolbar-row元素
垫控件在组件上工作正常,但页脚组件除外。 我正在尝试在共享页面页脚组件中使用Mat-toolbar和mat-toolbar-row。 我不知道为什么工具栏无法正确显示。 起初,我遇到了这个例外。
未捕获的错误:模板解析错误:'mat-toolbar-row'不是一个已知元素:1.如果'mat-toolbar-row'是Angular组件,则请验证它是否属于此模块。 2.如果“ mat-toolbar-row”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”以禁止显示此消息。 (”
然后我在以下页脚中添加了CUSTOM_ELEMENTS_SCHEMA,但异常消失了。
import { Component, NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
@Component({
selector: 'app-footer',
templateUrl: './footer.component.html',
styleUrls: ['./footer.component.scss']
})
export class Footer
{
getYear()
{
return new Date().getUTCFullYear();
}
}
@NgModule({
exports: [Footer],
declarations: [Footer],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class FooterModule { }
现在我在浏览器控制台中没有任何异常,我的应用程序正在运行,但是现在不显示mat-toolbar和mat-toolbar-row元素的颜色以及图标的效果。 应用程序只显示原始数据,然后准确显示。
我的页脚组件是:
<footer class="app-footer">
<div class="app-footer-link">
<p>
<span>VAA</span> © {{getYear()}}
<a href="https://www.VAA.com" target="_blank">www.VAA.com</a>
</p>
</div>
<mat-toolbar color="primary">
<mat-toolbar-row>
<span>Custom Toolbar</span>
</mat-toolbar-row>
<mat-toolbar-row>
<span>Second Line</span>
<span class="example-spacer"></span>
<mat-icon class="example-icon">verified_user</mat-icon>
</mat-toolbar-row>
<mat-toolbar-row>
<span>Third Line</span>
<span class="example-spacer"></span>
<mat-icon class="example-icon">favorite</mat-icon>
<mat-icon class="example-icon">delete</mat-icon>
</mat-toolbar-row>
</mat-toolbar>
</footer>
此外,我已经在Shared.module.ts中导入了MaterialModule,并且在app.module.ts中导入了共享模块。
我在App.Component.html上调用此页脚,而mat-toolbar在App.Component.html上运行良好。
请参阅对App.Component.html的调用。
<mat-sidenav-content>
<div fxLayout="column" fxFill>
<div id="mainContent" fxFlex>
<router-outlet></router-outlet>
</div>
<app-footer></app-footer>
</div>
</mat-sidenav-content>
</mat-sidenav-container>
这是主题效果逻辑:
@mixin footer-theme($theme) {
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$warn: map-get($theme, warn);
$background: map-get($theme, background);
$foreground: map-get($theme, foreground);
app-footer {
.app-footer {
background: mat-color($primary);
color: mat-color($primary, default-contrast);
}
.app-footer-link a {
color: mat-color($primary, default-contrast);
}
}
}
我想按原样显示此示例:请通过以下URL进行查看: https : //material.angular.io/components/toolbar/examples
这是因为您必须导入自定义模块中的组件正在使用的必要模块! 见下文:
@NgModule({
imports: [
CommonModule,
MatIconModule,
MatToolbarModule,
// ...
],
declarations: [
Footer,
// ...
]
})
export class FooterModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.