Currently in the process of enhancing the code of a webpage. Specifically, I want to provide users with different dropdown options once they are logged in. Using Angular, the corresponding component.ts file is structured as follows...
constructor () {
this.name = this.login ? 'User' : 'Guest';
...
this.list = [
{display: this.name, value: 'name'},
{display: this.address, value: 'address'},
{display: this.company, value: 'company'}
];
}
In the provided code snippet, the variable login is defined outside of the constructor. The issue I am facing is with the display value of this.name. Can ternary operators be effectively used within Typescript constructors? If not, what would be the ideal approach to handle the condition for the display value to dynamically change? I attempted to declare the list outside of the constructor, but it resulted in display issues on the webpage.