Get deployUrl from angular.json in component

时间:2019-04-08 12:55:40

标签: angular angular-universal

I know that it's possible to get baseUrl from angular.json using for example: platformLocation.getBaseHrefFromDOM(). Is there any way to get deployUrl inside component in Angular 7?

I am working on some speed improvements and I am storing my styling files using cdn, so it's stored at deploy-url/styles.js. I have to load this inside app.component.ts (lazy-loading styles) but I need full url for that.

1 个答案:

答案 0 :(得分:0)

I don't know what deployUrl is or where it is stored but if its inside a JSON file you can read the JSON file inside your environment.ts file and then access it via your environment but this might break AOT if you are using AOT so be careful.

Alternatively, just read the JSON file in the component that wants the data.

To read a JSON file:

import * as myJson from './path/my-file.json'

then:

console.log(myJson.deployUrl)