
This commit provides a replacement for `$location`. The new service is written in Angular, and can be consumed into existing applications by using the downgraded version of the provider. Prior to this addition, applications upgrading from AngularJS to Angular could get into a situation where AngularJS wanted to control the URL, and would often parse or se rialize the URL in a different way than Angular. Additionally, AngularJS was alerted to URL changes only through the `$digest` cycle. This provided a buggy feedback loop from Angular to AngularJS. With this new `LocationUpgradeProvider`, the `$location` methods and events are provided in Angular, and use Angular APIs to make updates to the URL. Additionally, change s to the URL made by other parts of the Angular framework (such as the Router) will be listened for and will cause events to fire in AngularJS, but will no longer attempt to update the URL (since it was already updated by the Angular framework). This centralizes URL reads and writes to Angular and should help provide an easier path to upgrading AngularJS applications to Angular. PR Close #30055
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
export function stripPrefix(val: string, prefix: string): string {
|
|
return val.startsWith(prefix) ? val.substring(prefix.length) : val;
|
|
}
|
|
|
|
export function deepEqual(a: any, b: any): boolean {
|
|
if (a === b) {
|
|
return true;
|
|
} else if (!a || !b) {
|
|
return false;
|
|
} else {
|
|
try {
|
|
if ((a.prototype !== b.prototype) || (Array.isArray(a) && Array.isArray(b))) {
|
|
return false;
|
|
}
|
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
export function isAnchor(el: (Node & ParentNode) | Element | null): el is HTMLAnchorElement {
|
|
return (<HTMLAnchorElement>el).href !== undefined;
|
|
}
|
|
|
|
export function isPromise(obj: any): obj is Promise<any> {
|
|
// allow any Promise/A+ compliant thenable.
|
|
// It's up to the caller to ensure that obj.then conforms to the spec
|
|
return !!obj && typeof obj.then === 'function';
|
|
}
|