angular.js - Angular 2: 如何在运行时自动引入 normalize.css 文件?
问题描述
最近学习 Angular 2 的时候发现 HTML 5 的通病 body margin:8px 依然存在,就像引入 normalize.css 丢弃这些不需要的样式。
传统的方式是直接引入 .css 文件,如:<link rel='stylesheet' href='https://www.haobala.com/wenda/node_modules/normalize.css/normalize.css' /> ,但是我现在想让 Angular 通过 import 模块的方式自动为 index.html 引入 normalize.css 样式表。
我先是按照之前引入 Material 2 的方式:
// angular-cli-build.jsmodule.exports = function(defaults) { return new Angular2App(defaults, { vendorNpmFiles: [ ’normalize-path/index.js’, ] });};
// system-config.ts const map: any = { ’normalize’: ’vendor/normalize-path’,};/** User packages configuration. */const packages: any = { ’normalize’: {main: ’index.js’},};
// app.component.tsimport { normalize } from ’normalize-path’;
这时编辑器会提示:
Cannot find module ’normalize-path’.
并且编译也不通过,也许我的出发点是错的。
我尝试去 stackoverflow 寻找答案但是没有找到,Google 也没找到相关问题的博文或讨论。
问题解答
回答1:oc.lazyLoad试试
回答2:建议使用angular-cli来开发在.angular-cli.json中配置:
'styles': ['styles.css','../node_modules/normalize.css/normalize.css' ]
相关文章:
1. 老师们php,插入数据库mysql,都是空的,要怎么解决2. python如何转换时间戳到"2017年6月12日 18点24分"这样的格式呢?3. php - 有关sql语句反向LIKE的处理4. theano import error (win10 python2.7)5. python3.x - 请问python3如何比较稳妥地使用多进程在向同一个日志中写日志呢6. javascript - 微信小程序不支持<br> <p>等标签7. find_in_set - 请教 mysql查询8. mysql - owncloud 数据库错误 1045,太奇怪了。9. php由5.3升级到5.6后,登录网站,返回的是php代码,不是登录界面,各位大神有知道的吗?10. objective-c - 同一个APP的微信登录的微信开发平台账号和微信支付的微信开发平台账号可以是不同一个吗?

网公网安备