简体   繁体   English

materializecss + Angular 6 如何配置?

[英]materializecss + Angular 6 how to configure?

I am new to Angular in general and I am trying to use materializecss with Angular 6. I am using CLI to create my components.我是 Angular 的新手,我正在尝试在 Angular 6 中使用materializecss 。我正在使用 CLI 创建我的组件。

I have read materials about how to do it in Angular 2, but Angular 6 seems to be different, for instance not having angular-cli.json file.我已经阅读了有关如何在 Angular 2 中执行此操作的材料,但 Angular 6 似乎有所不同,例如没有 angular-cli.json 文件。

How can I get materializecss running in Angular 6?如何在 Angular 6 中运行 materializecss?

Command used to install materializecss: npm i materialize-css@next用于安装 materializecss 的命令: npm i materialize-css@next

angular.json attempted modification: angular.json 尝试修改:

           "styles": [
              "./node_modules/materialize-css/dist/css/materialize.css",
              "src/styles.scss"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.min.js",
              "./node_modules/materialize-css/dist/js/materialize.js"
            ]

This alone did not work.仅此一项是行不通的。

Have you tried ngx-materialize ?你试过ngx-materialize吗?

their instructions suggests that you also need to alter the tsconfig.json file and add the following to the types array:他们的说明建议您还需要更改 tsconfig.json 文件并将以下内容添加到 types 数组:

  • "jquery", "jquery",
  • "materialize-css" “物化CSS”

unless you are looking for a specific component I would suggest angular-material as a better alternative.除非您正在寻找特定组件,否则我建议使用angular-material作为更好的选择。

There are a few ways of using materialize styles in Angular.在 Angular 中有几种使用实体化样式的方法。
To list some:列出一些:

  1. Download angular specific css frameworks-see npm for angular compatible css frameworks.下载特定于Angular 的css 框架 - 有关Angular兼容的 css 框架,请参阅npm
  2. Download the source code from the materialize-css website and paste it into any of the components css file.materialize-css网站下载源代码并将其粘贴到任何组件 css 文件中。
  3. Download the npm package of materialize by typing npm install materialize-css@next into the terminal.通过在终端中输入 npm install materialize-css@next 来下载 materialize 的 npm 包。

Note:笔记:

Some features of materialize-css require jquery. materialize-css 的一些特性需要 jquery。 I'm currently having issues in Angular when I nmp install jquery... 当我 nmp 安装 jquery 时,我目前在 Angular 中遇到问题...
materialize-css styling and colors can however still be used in components which don't require animations. 然而,materialize-css 样式和颜色仍然可以在不需要动画的组件中使用。

A word on Angular specific packages:关于 Angular 特定包的一句话:

ngx-materialize is great for easy installation,component styling and animations but has deprecated dependencies. ngx-materialize非常适合易于安装、组件样式和动画,但已弃用依赖项。

materialize-angular is also good, but is currently not backed by any organisations and therefore too has many out-of-date dependencies. materialize-angular也不错,但目前没有任何组织支持,因此也有许多过时的依赖项。

If you don't know exactly why you might need an angular specific css framework, consider using the vanilla Materialize or Bootstrap frameworks.如果您不确切知道为什么您可能需要特定于角度的 css 框架,请考虑使用 vanilla Materialize 或 Bootstrap 框架。

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

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