Wenn meine URL http://www.something.com/foo/bar/index.html?color=yellow&animal=rat
Ist, sieht es so aus:
$location.path()
gibt foo/bar/index.html
zurück$location.absUrl()
gibt http://www.something.com/foo/bar/index.html?color=yellow&animal=rat
zurück$location.url()
gibt foo/bar/index.html?color=yellow&animal=rat
zurückGibt es eine Funktion, die http://www.something.com/foo/bar/index.html
Zurückgibt?
Oder muss ich das selbst mit Funktionen wie Protokoll, Host, Port usw. konstruieren (oder die Abfrageparameter selbst entfernen)?
Soweit ich weiß, müssen Sie es selbst bauen. Nicht, dass Sie gefragt hätten, wie man es baut, sondern für diejenigen, die sich fragen:
var url = $location.absUrl().split('?')[0]
Nicht, dass dies die Notwendigkeit beseitigt, es selbst zu konstruieren, nur eine andere Möglichkeit, dasselbe zu tun. Wenn Sie ein window.location-Objekt verwenden, können Sie einfach window.location.Origin + window.location.pathname sagen
window.location-Objekt hat
Host:"localhost.abc.com:8080"
hostname:"localhost.abc.com"
href:"http://localhost.abc.com:8080/quickpick/repossessions/?displayStr=Repossessions&from=%2F&page=1"(whole url)
Origin:"http://localhost.abc.com:8080"
pathname:"/quickpick/repossessions/"
port:"8080"
protocol:"http:"