1

In index.html

<script>
    var variable='some value';
</script>

How can I access variable in angular code? I tried windows.variable, which come with compiling error. I've seen $window.variable on angular 2. But I can't find any usage of $window in angular 4. Is there any solution to get access to pre-defined variable in html code with angular 4?

6
  • 2
    use var instead of const for global variables, const variables are not attached to the window object Commented Jul 14, 2017 at 5:55
  • @Maximus ty for tip, but using var didn't solve my problem Commented Jul 14, 2017 at 5:57
  • what was your problem? Commented Jul 14, 2017 at 5:59
  • I need to fetch variable in my angular service code @Maximus Commented Jul 14, 2017 at 6:01
  • 1
    Just put the code 'declare var variable:any' to your Angular code like described here stackoverflow.com/questions/44170294/… Commented Jul 14, 2017 at 6:01

0

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.