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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.