简体   繁体   English

角形材料组件

[英]Material components for angular with routing

I'm attempting to use Material components for angular ( https://blox.src.zone/material#/guides/gettingstarted ) in my Angular 4.3 app. 我正在尝试在Angular 4.3应用程序中将Material组件用于angular( https://blox.src.zone/material#/guides/gettingstarted )。 I've installed everything and I added a button to my app.component.html file and the button is rendered and behaves like it should here https://blox.src.zone/material#/directives/button . 我已经安装了所有内容,并在app.component.html文件中添加了一个按钮,该按钮已呈现并表现为应该在这里https://blox.src.zone/material#/directives/button

I've then tried adding a button in one of my routes and the button isn't rendered the same. 然后,我尝试在我的一条路线中添加一个按钮,但该按钮未呈现相同的效果。 It's like the bootstrap css has taken over. 就像引导css已经接管了。

Do I have to import anything in the components that I'm routing to? 我必须在要路由到的组件中导入任何内容吗?

There's not near enough information to answer your question. 没有足够的信息来回答您的问题。 (How do you build your project, where did you put the stylesheets for the material components, do you use webpack, angular cli, rollup, or some other build tool, etc.). (如何构建项目,在何处放置材料组件的样式表,使用webpack,angular cli,汇总或其他构建工具等)。 But since I can't comment (not enough reputation), I will give it a try. 但是由于我无法发表评论(声誉不足),因此我将尝试一下。

From your description, it sounds like you added the stylesheets (probably css or scss) to a single app component, via a styleUrls declaration in your @Component metadata. 从您的描述中,听起来就像您通过@Component元数据中的styleUrls声明将样式表(可能是css或scss)添加到了单个应用程序组件中。 Angular by default encapsulates styles for a component, so in that case your styles only apply to your app component. 默认情况下,Angular封装了组件的样式,因此在这种情况下,您的样式仅适用于您的应用程序组件。

For a Blox Material project you typically want to add the material components stylesheets as application wide stylesheet, included in your html via a script tag. 对于Blox Material项目,您通常希望将材料组件样式表添加为应用程序范围的样式表,并通过script标签将其包含在html中。 When your project is an Angular-CLI project this is the file named in the "styles" field for your app as given in the .angular-cli.json file. 当您的项目是Angular-CLI项目时,这是.angular-cli.json文件中给定的应用程序的“样式”字段中.angular-cli.json文件。 This is also what the getting started guide for Blox Material describes, see https://blox.src.zone/material#/guides/gettingstarted . 这也是Blox Material入门指南所描述的内容,请参阅https://blox.src.zone/material#/guides/gettingstarted

Alternatively you could put the stylesheet in the root component of your app and/or play with encapsulation: ViewEncapsulation.None in your @Component metadata, to make the styles apply to multiple components at the same time. 或者,您可以将样式表放在应用程序的根组件中和/或使用encapsulation: ViewEncapsulation.None@Component元数据中encapsulation: ViewEncapsulation.None ,以使样式同时应用于多个组件。

If this doesn't help, please provide a bit more information, and try to use your developer tools to see what styles (and by which selectors) get applied to your app component. 如果这样做没有帮助,请提供更多信息,并尝试使用开发人员工具查看将哪些样式(以及通过哪些选择器)应用于您的应用程序组件。 That will probably give you clues as why they don't get applied to your other components. 这可能会为您提供线索,说明为什么它们没有应用于您的其他组件。 It will also tell you if other styles (such as for bootstrap, are overriding the material component styles). 它还会告诉您其他样式(例如引导程序)是否覆盖了材料组件样式。

Finally check that the Blox Material directives are actually being applied to your buttons: An mdcButton should automatically get at least the mdc-button and mdc-ripple-upgraded style. 最后,检查是否确实将Blox Material指令应用于按钮:mdcButton应该至少自动获得mdc-buttonmdc-ripple-upgraded样式。 If you don't see these styles on the button, there is something wrong with how you applied the mdcButton directive. 如果您在按钮上看不到这些样式,则您应用mdcButton指令的方式有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM