<!doctype html> <html lang="en"> <head> <Meta charset="utf-8"> <title>Ng2</title> <base href="/"> <Meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" type="text/css" href="../node_modules/font-awesome/css/font-awesome.min.css" /> <link rel="stylesheet" type="text/css" href="../node_modules/primeng/resources/themes/omega/theme.css" /> <link rel="stylesheet" type="text/css" href="../node_modules/primeng/resources/primeng.min.css" /> </head> <body> <app-root></app-root> </body> </html>
在.angualr.json配置就无效
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json","project": { "name": "ng2" },"apps": [ { "root": "src","outDir": "dist","assets": [ "assets","favicon.ico" ],"index": "index.html","main": "main.ts","polyfills": "polyfills.ts","test": "test.ts","tsconfig": "tsconfig.app.json","testTsconfig": "tsconfig.spec.json","prefix": "app","styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css","../node_modules/font-awesome/css/font-awesome.min.css","styles.css" ],"scripts": [],"environmentSource": "environments/environment.ts","environments": { "dev": "environments/environment.ts","prod": "environments/environment.prod.ts" } } ],"e2e": { "protractor": { "config": "./protractor.conf.js" } },"lint": [ { "project": "src/tsconfig.app.json","exclude": "**/node_modules/**" },{ "project": "src/tsconfig.spec.json",{ "project": "e2e/tsconfig.e2e.json","exclude": "**/node_modules/**" } ],"test": { "karma": { "config": "./karma.conf.js" } },"defaults": { "styleExt": "css","component": {} } }
1、.angular-cli.json是配置文件,修改需要重新启动服务。
2、使用cnpm创建目录,我遇到这样的情况无法加载css;
使用 ng new myApp,创建好目录,马上要开始初始化node_modules,默认会使用npm创建node_modules
cmd + c,停止创建。
cnpm install 使用cnpm创建node_modules
配置 .angular-cli.json文件,css不起作用,js也不起作用。
最后删除项目,配置npm国内淘宝镜像
1.临时使用
npm --registry https://registry.npm.taobao.org install express
2.持久使用
npm config set registry https://registry.npm.taobao.org
// 配置后可通过下面方式来验证是否成功
npm config get registry
然后使用 ng new myApp 直到结束,cd myApp; ng serve 运行项目,修改配置,没问题了。
好像就是angular-cli对cnpm支持不太好,还是使用npm的好。3、当然你需要安装响应的包才行。
原文链接:https://www.f2er.com/angularjs/146375.html