Angular 4/2中的方法重载
发布时间:2020-12-17 18:00:04 所属栏目:安全 来源:网络整理
导读:我现在正在使用Angular 4.我没有在Angular 2或4中找到任何关于方法重载的正确解决方案.是否有可能在角度服务类中实现方法重载?或者我有兴趣知道它的细节.提前致谢. 我刚刚尝试像下面那样创建服务但发现Dublicate函数实现错误 ApiService.ts: import { Inje
我现在正在使用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); } } 解决方法
而不是重载方法,使令牌参数可选.
postCall(url,token?) { // with three parameters return resultFromServer; } 希望能帮助到你 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |