我是angular的初学者。我从angular 6开始,目前无法理解如何在angular项目中使用我的index.html来制作可配置的cdn路径。
请看我的代码::
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Refman</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" href="https://cdn1.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn2.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<app-root></app-root>
</body>
</html>
我想让这些cdn1和cdn2成为可配置的。这意味着我想从我的config.json中读取cdn路径和cdn的基本url。如何从.json文件中使用此路径读取它们。
请帮帮我。提前谢谢。
发布于 2018-09-04 15:58:05
Angular建议使用环境变量来管理您需要的动态变量和配置。
environment.ts
environment.prod.ts
……自定义环境
http://tattoocoder.com/angular-cli-using-the-environment-option/
https://medium.com/@amcdnl/custom-environments-for-angular-cli-4ce0b82da83b
结构:
发布于 2018-09-04 15:46:59
您需要将环境类导入到index.html所在的组件中:
import { environment } from 'location of environment.ts'然后以这种方式传递类变量:
public pName = environment.propertyname; // .css or a URL在index.html中,将pName传递给href:
<link rel="stylesheet" href="pName">https://stackoverflow.com/questions/52160325
复制相似问题