You are trying to access properties of the class definition. What you want is to access the properties of the class instance. To instanciate a class, you have to use the new keyword:
const userRole = new UserRoleDto();
This executes the classes constructor function and will create an instance of your class which is stored in the userRole variable. You can have multiple instances of your class. You can access public properties of your class and (if they are not readonly) you can assign values to them.
userRole.userRole = 'Admin';
console.log(userRole.userRole) // prints 'Admin'
By default your class properties do not have any values assigned if you do not define them in your class. You can do so by
export class UserRoleDto {
userRole = 'Admin';
}
Angular Dependency Injection
The Angular dependency injection is able to construct your classes intelligently without the need to instantiate them manually. If these classes are known by the DI of the corresponding module, you can inject them by defining parameters of your constructor.
I think what you want is a service (a class known by the DI) which can store data module-wide, not component wide.
import { Injectable } from '@angular/core';
@Injectable()
export class UserRoleService {
userRole = 'Admin';
}
In your module where you also declare your component you have to define it in the providers array.
@NgModule({
...
providers: [
UserRoleService
]
})
And in your component you can then inject the service as follows
export class SettingDataComponent {
showAnalytics = false;
constructor(private userRoleService: UserRoleService) {
if(userRoleService.userRole === "Admin")
this.showAnalytics = true;
}
}