Answer the question
In order to leave comments, you need to log in
Is there a way to create a config file that can be used across all components and services in angular 7?
What would I like.
Create a class MainConfig with a set of properties and then use it in all components/services of the application.
Something like this.
File /src/app/main.config.ts:
export class MainConfig {
prodUrl: string;
constructor() {
this.prodUrl = 'https://site.api';
}
}
import { MainConfig } from '../main.config';
export class ApiService {
constructor(private mainConfig: MainConfig) { }
res = this.myMethod(this.mainConfig.prodUrl){....}
}
Answer the question
In order to leave comments, you need to log in
Create a service, store data in it and inject it everywhere. What is the problem.
Everything is like in your example, only
@Injectable({
providedIn: 'root'
})
export class MainConfig {
// данные
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question