I have a component ts file in which it is reusable by 2 HTML - one for privileged users and one for non-privileged users. Both HTMLs calls/reuse the same component ts file. However, I have 2 APIs - one for privileged and one for non-privileged. How do I integrate both APIs when the HTMLs are reusing the same component file?
CodePudding user response:
you can check this using if
statement and when condition is met call the respective API as needed.
CodePudding user response:
You should have a service for the API calls (https://angular.io/guide/architecture-services)
Then you can pass values to the component through @Input() (https://angular.io/guide/component-interaction)
In the component you decide which call you make based on the input
CodePudding user response:
HTML and Typescript class forms one whole in Angular. One component, one html.
You can alter html structure with structural directives *ngIf
or ngSwitch
or your own directives at runtime.
Or you can create two different components for privileged and non-privileged users (move common functionality to service), altough maintainig one component can be simpler than two.