Skip to content

Commit 05219a5

Browse files
committed
feat(dom): add getBaseHref method
1 parent 4b62a72 commit 05219a5

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

modules/angular2/src/dom/browser_adapter.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
318318
getLocation() {
319319
return window.location;
320320
}
321+
getBaseHref() {
322+
var uri = document.baseUri;
323+
var baseUri = Uri.parse(uri);
324+
return baseUri.path;
325+
}
321326
}

modules/angular2/src/dom/browser_adapter.es6

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,17 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
381381
getLocation() {
382382
return window.location;
383383
}
384+
getBaseHref() {
385+
return relativePath(document.baseURI);
386+
}
387+
}
388+
389+
// based on urlUtils.js in AngularJS 1
390+
var urlParsingNode = null;
391+
function relativePath(url) {
392+
if (isBlank(urlParsingNode)) {
393+
urlParsingNode = document.createElement("a");
394+
}
395+
urlParsingNode.setAttribute('href', url);
396+
return (urlParsingNode.pathname.charAt(0) === '/') ? urlParsingNode.pathname : '/' + urlParsingNode.pathname;
384397
}

modules/angular2/src/dom/dom_adapter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,7 @@ export class DomAdapter {
292292
getLocation() {
293293
throw _abstract();
294294
}
295+
getBaseHref() {
296+
throw _abstract();
297+
}
295298
}

modules/angular2/src/dom/html_adapter.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,7 @@ class Html5LibDomAdapter implements DomAdapter {
297297
getLocation() {
298298
throw 'not implemented';
299299
}
300+
getBaseHref() {
301+
throw 'not implemented';
302+
}
300303
}

0 commit comments

Comments
 (0)