Angular2(angular

编程入门 行业动态 更新时间:2024-10-26 06:26:24
本文介绍了angular2(angular-cli)和Material Design Lite(angular2-mdl)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用angular2-mdl包启动Angular2项目时遇到了一些问题.

I'm having some issues starting an Angular2 project using the angular2-mdl package.

我的项目设置使用angular-cli(webpack)- github/angular /angular-cli

My project setup is using angular-cli (webpack) - github/angular/angular-cli

我正在尝试集成Google Material Design Lite( getmdl.io/started/index .html ),使用angular2-mdl程序包( www.npmjs. com/package/angular2-mdl ).

I am trying to integrate Google Material Design Lite (getmdl.io/started/index.html) using the angular2-mdl package (www.npmjs/package/angular2-mdl).

angular2-mdl设置步骤非常简单:

The angular2-mdl setup steps are fairly simple:

npm install angular2-mdl --save

显然是这样...它应该可以工作.但事实并非如此.我已经指出使用MDL的组件的样式正确,但是动画的JavaScript根本无法启动.我了解这是因为MDL在Angular将页面加载到DOM元素之前正在扫描页面中的DOM元素,所以尝试按照SO上的说明尝试刷新DOM"修复,但对我不起作用:

Apparently that is it... and it should work. But it doesn't. I've got to a point where the components using MDL are styled correctly, but the JavaScript for animations doesn't fire at all. I understand this is because MDL is scanning the page for DOM elements before Angular loads them in, so have tried the 'refresh DOM' fix as advertised on SO but it's not working for me:

ngAfterViewInit(){ console.log("HeaderComponent.ngAfterViewInit"); componentHandler.upgradeAllRegistered(); }

控制台中没有错误,样式有效,而javascript则无效.我想知道是否有人对此设置/类似问题有经验?

There are no errors in the console, the styling works and the javascript does not. I'm wondering if anyone has experience with this setup / similar issues?

P.s.我是Angular2的新手,真的不喜欢每种环境设置似乎都存在的差异...有些使用webpack,有些使用systemjs,负载了许多生成器工具,等等...我一个人在这里吗?!

P.s. I'm new to Angular2 and really not enjoying the differences every environment setup seems to have... with some using webpack, some using systemjs, loads of different generator tools etc... am I alone here?!

谢谢

推荐答案

在您已经安装angular-cli并创建了项目之后 使用以下命令安装material-desgin-lite:

after you already installed angular-cli and created a project install material-desgin-lite with:

npm install material-design-lite --save

一旦完成安装,请在项目的根目录上打开.angular-cli.json并添加以下行:

Once intalled open the .angular-cli.json on the root directory of your project and add the following lines:

"styles": ["../node_modules/material-design-lite/material.min.css"], "scripts": ["../node_modules/material-design-lite/material.min.js"],

保存文件并使用以下命令启动服务器: ng serve

Save the file and the start the server with: ng serve

在代码中使用所需的CSS类和其他组件.

Use the desired css classes and other components in your code.

更多推荐

Angular2(angular

本文发布于:2023-11-01 17:38:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!