0

How can I use a variable defined in a typescript file of a component, in my index.html file in angular 4?

3
  • 1
    <p>{{nameOfVariable}}</p> Commented Mar 27, 2018 at 10:58
  • 1
    @messerbill, but only if the name of the variable is "nameOfVariable" :D Commented Mar 27, 2018 at 11:02
  • and so far your <app-root></app-root> is called in your index.html you cannot access any variables out of the app. Use app.component.html instead Commented Mar 27, 2018 at 11:07

1 Answer 1

3

you cannot use this in index.html directly but you can use this by assigning the value in a component.ts file like

yourvariable : string;

and use this variable only in a component.html file which is been of the same type.

like {{yourvariable}}

you can also access this variable to any component.

in angular index.html is the starting point of view in which there is component based div structure. you can add variable there using above procedure.

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.