I have a view rendering written in .cshtml. The .cshtml in turn refers .js files (written as angular2 apps). I want to pass a parameter from the .cshtml to the angular2 app. How do I do this? I am using angular-cli to generate the angular2 app.
Passing parameter to angular2 app from a .cshtml view rendering in SiteCore
212 views Asked by user3547774 At
2
There are 2 answers
0
On
Jens answer will definitely work. You could also pull the data with a separate call through Sitecore Service Client in Angular if you are concerned with adding variables to global scope or don't want to have additional dependencies on the view. This will have a small performance impact as an additional request would need to be made.
I would just output the value in a JavaScript namespace inside a script tag in your view/controller rendering and then use that in your Angular app. Eg. output this:
Then you can just access the solution.vars.myVariable in your other JavaScript.