refactor(core): remove getters for packages/animations, language-service, platform-browser, router (#19151)

PR Close #19151
This commit is contained in:
Yuan Gao
2017-09-11 12:39:44 -07:00
committed by Igor Minar
parent 17eaef0311
commit 549f2254b4
13 changed files with 109 additions and 119 deletions

View File

@ -23,7 +23,7 @@ import {supportsState} from './history';
*/
@Injectable()
export class BrowserPlatformLocation extends PlatformLocation {
private _location: Location;
public readonly location: Location;
private _history: History;
constructor(@Inject(DOCUMENT) private _doc: any) {
@ -34,12 +34,10 @@ export class BrowserPlatformLocation extends PlatformLocation {
// This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
/** @internal */
_init() {
this._location = getDOM().getLocation();
(this as{location: Location}).location = getDOM().getLocation();
this._history = getDOM().getHistory();
}
get location(): Location { return this._location; }
getBaseHrefFromDOM(): string { return getDOM().getBaseHref(this._doc) !; }
onPopState(fn: LocationChangeListener): void {
@ -50,16 +48,16 @@ export class BrowserPlatformLocation extends PlatformLocation {
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
}
get pathname(): string { return this._location.pathname; }
get search(): string { return this._location.search; }
get hash(): string { return this._location.hash; }
set pathname(newPath: string) { this._location.pathname = newPath; }
get pathname(): string { return this.location.pathname; }
get search(): string { return this.location.search; }
get hash(): string { return this.location.hash; }
set pathname(newPath: string) { this.location.pathname = newPath; }
pushState(state: any, title: string, url: string): void {
if (supportsState()) {
this._history.pushState(state, title, url);
} else {
this._location.hash = url;
this.location.hash = url;
}
}
@ -67,7 +65,7 @@ export class BrowserPlatformLocation extends PlatformLocation {
if (supportsState()) {
this._history.replaceState(state, title, url);
} else {
this._location.hash = url;
this.location.hash = url;
}
}