the project I’m working on is a wordpress plugin which display an angular application. in order to do that, I prerender the angular application with Static Site Generation and put the result in the wordpress extension.
on the start of the application, I need to send the root url from wordpress to the angular application but I don’t have found how to do that.
I tried a javascript global variable :
<script>
const server = "https:/domain/directory";
</script>
<app-root></app-root>
I tried also passing the value in a tag parameter :
<app-root server="https:/domain/directory"></app-root>
<app-root [server]="https:/domain/directory"></app-root>
in all theses tries, I don’t have found how to read this value in angular.
have somebody an idea how to do that ?
2
Answers
I found a way of passing values.
In html code, I set this :
and to read the value in the component (app.component.ts), I use this :
The typical is declare a variable in your component.ts (but outside the component)
If it’s a variable that you use so much you can create in a .ts a function
This allow that if you want to change the variable in the script not need look for in all yours components or services the "declare var".
In your component or service or whatever