0

I'm have a generated value on the page (pageId) which is added inline in a script tag.

<script>
var pageId = @Model.Id
</script>

I then want to use this value in some Typescript (Angular App). Obviously I get an error it's not defined. Do can I define it so it's assumed it's present on the page?

John Churchley
  • 434
  • 4
  • 17
  • Possible duplicate of [How to access global js variable in angular2 component](https://stackoverflow.com/questions/37662794/how-to-access-global-js-variable-in-angular2-component) – Gordon Westerman Oct 30 '18 at 10:52

1 Answers1

1

You are trying to access a global variable. Angular best practice for accessing global variables is to provide them through dependency injection like you would a service.

This has already been answered before, if it helps please mark Thierry Templier's answer as useful.

Gordon Westerman
  • 1,046
  • 10
  • 12