我知道通过以下代码行我们可以获取域名,但不确定如何获取端口号。有人可以帮助我吗
//importing
import { DOCUMENT } from '@angular/platform-browser';
//Injection
export class domainUtil {
domain:string;
constructor(@Inject(DOCUMENT) private document: any) { }
returnHostname(){
this.domain = this.document.location.hostname;
console.log("*****Domain Name*******"+this.domain);//Returning domain name
}
}
document.location.port
在角度中,它将是
this.port = this.document.location.port;