Currently, I am working on Angular 4 and have been struggling to find a suitable solution for method overloading in Angular 2 or 4. Can we actually implement method overloading in an Angular service class? I would really appreciate if someone could provide more insights on this topic. Thank you.
I attempted to create a Service as shown below but encountered a Duplicate function implementation error
ApiService.ts :
import { Injectable } from '@angular/core';
@Injectable()
export class ApiService {
constructor() { }
postCall(url, data, token) { // with three parameters
return resultFromServer; }
postCall(url, data) { // with two parameters
return resultFromServer;}
}
AuthenticationService.ts:
import { Injectable } from '@angular/core';
import { ApiService } from "app/_services/api.service";
import FunUtils from "app/_helper/utils";
@Injectable()
export class AuthenticationService {
constructor(private api: ApiService) { }
rest_login_call(userName, password) {
let data = { username: userName, password: password };
let url = "http://localhost:8000";
return this.api.postCall(url, data);
}
}