Suppose I am looking to efficiently reuse my Angular 2 components, how can I input configuration directly into the HTML and then pass it to the respective class? However, could this method be vulnerable to potential manipulation in the HTML code by unauthorized users? What would be considered the optimal approach in Angular 2 for creating multiple instances of the same class with varied configurations?
I am facing two main issues:
- I am only receiving one console output. Does this imply that the class is static in nature?
- The console output I receive shows as null.
Considering the following code snippets:
<my-comp showWhat="INCOMING"></my-comp>
<my-comp showWhat="OUTGOING"></my-comp>
How can I effectively pass the values 'INCOMING' or 'OUTGOING' to the constructor function?
@Component({
selector: 'my-comp'
[..]
})
export class MyComponent {
constructor(elementRef: ElementRef) {
console.log("Creating an instance: showWhat value for this instance = "+elementRef.nativeElement.getAttribute('showWhat'));
}
}