Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
allocine-exemple-webb-app-front
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
formation-dev-web
allocine-exemple-webb-app-front
Merge requests
!1
add overriding environment
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
add overriding environment
feat/modify-environment
into
main
Overview
0
Commits
2
Pipelines
2
Changes
8
Open
add overriding environment
Mohammed Rachid BENHAMMOU
requested to merge
feat/modify-environment
into
main
May 28, 2024
Overview
0
Commits
2
Pipelines
2
Changes
8
0
0
Merge request reports
Compare
main
version 1
597a532b
May 28, 2024
main (HEAD)
and
latest version
latest version
21352ee8
2 commits,
May 28, 2024
version 1
597a532b
1 commit,
May 28, 2024
8 files
+
52
−
8
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
src/app/core/environment-init.ts
0 → 100644
+
32
−
0
View file @ 68427bb2
Edit in single-file editor
Open in Web IDE
import
{
APP_INITIALIZER
,
InjectionToken
,
Provider
}
from
"
@angular/core
"
;
import
{
lastValueFrom
,
map
,
ReplaySubject
}
from
"
rxjs
"
;
import
{
merge
}
from
"
lodash
"
;
import
{
HttpClient
}
from
'
@angular/common/http
'
;
import
{
environment
}
from
"
src/environments/environment
"
;
import
{
Environment
}
from
"
src/environments/environment.model
"
;
export
const
ENVIRONMENT
=
new
InjectionToken
(
'
env
'
);
const
environmentSubject
=
new
ReplaySubject
<
Environment
>
(
1
);
const
environment$
=
environmentSubject
.
asObservable
();
export
const
ENVIRONMENT_INITIALIZER
:
Provider
[]
=
[
{
provide
:
APP_INITIALIZER
,
useFactory
:
environmentInitializer
,
multi
:
true
,
deps
:
[
HttpClient
],
},
{
provide
:
ENVIRONMENT
,
useValue
:
environment$
},
];
export
function
environmentInitializer
(
http
:
HttpClient
):
()
=>
Promise
<
Environment
>
{
return
()
=>
{
let
res
=
http
.
get
<
Environment
>
(
'
/assets/environment.json
'
)
.
pipe
(
map
(
e
=>
merge
(
environment
,
e
)));
res
.
subscribe
(
environmentSubject
);
return
lastValueFrom
(
res
);
};
}
\ No newline at end of file
Loading