我现在正在使用Angular 4.我没有在Angular 2或4中找到任何关于方法重载的正确解决方案.是否有可能在角度服务类中实现方法重载?或者我有兴趣知道它的细节.提前致谢.
我刚刚尝试像下面那样创建服务但发现Dublicate函数实现错误
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); } }