Now update the logout button in the header.component.html file to show the value of our variable.
See those double curly braces? This how you pass data from JavaScript/TypeScripts to html in Angular. It’s a one-way deal, nothing gets sent back to the TypeScript file, and it’s updated in real time. If the value of “nameToDisplay” was to change for any reason, that change would be immediately reflected in the HTML file.
Passing Functions in Angular
If you think back to react, you may remember, running functions onClick, Angular does things similarly but the syntax is a bit different. Edit your header.component.html to look like the following:
Angular knows that when it receives a click, to run the function (either called login or logout). So, let's define those methods so it can use them. Add the following in your header.component.ts file, underneath your ngOnInit but still inside of your component.
Let's also, have nameToDisplay start out as an empty string. Your whole header.component.ts file should look like this:
Now, open up your app in the browser, and click login and type your name. Make sure that it correctly displays your name, and that when you click logout it clears your name.