docs(Location): updating Location docs and adding example
closes #11500
This commit is contained in:

committed by
Victor Berchet

parent
2a5012d515
commit
20bed46737
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../_common/e2e_util';
|
||||
import {browser, by, element, protractor} from 'protractor';
|
||||
|
||||
|
||||
function waitForElement(selector: string) {
|
||||
var EC = (<any>protractor).ExpectedConditions;
|
||||
// Waits for the element with id 'abc' to be present on the dom.
|
||||
browser.wait(EC.presenceOf($(selector)), 20000);
|
||||
}
|
||||
|
||||
describe('Location', () => {
|
||||
afterEach(verifyNoBrowserErrors);
|
||||
|
||||
var URL = '/common/location/ts/#/bar/baz';
|
||||
|
||||
it('should verify paths', () => {
|
||||
browser.get(URL);
|
||||
waitForElement('hash-location');
|
||||
expect(element.all(by.css('path-location code')).get(0).getText())
|
||||
.toEqual('/common/location/ts');
|
||||
expect(element.all(by.css('hash-location code')).get(0).getText()).toEqual('/bar/baz');
|
||||
});
|
||||
});
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
// #docregion LocationComponent
|
||||
import {HashLocationStrategy, Location, LocationStrategy} from '@angular/common';
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'hash-location',
|
||||
providers: [Location, {provide: LocationStrategy, useClass: HashLocationStrategy}],
|
||||
template: `
|
||||
<h1>HashLocationStrategy</h1>
|
||||
Current URL is: <code>{{location.path()}}</code><br>
|
||||
Normalize: <code>/foo/bar/</code> is: <code>{{location.normalize('foo/bar')}}</code><br>
|
||||
`
|
||||
})
|
||||
export class HashLocationComponent {
|
||||
location: Location;
|
||||
constructor(location: Location) { this.location = location; }
|
||||
}
|
||||
// #enddocregion
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
// #docplaster
|
||||
// #docregion hash_location_strategy
|
||||
import {HashLocationStrategy, LocationStrategy} from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
// #enddocregion hash_location_strategy
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
// #docregion hash_location_strategy
|
||||
@NgModule({providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}]})
|
||||
class AppModule {
|
||||
}
|
||||
// #enddocregion hash_location_strategy
|
||||
export function main() {
|
||||
describe('hash_location_strategy examples', () => {
|
||||
let locationStrategy: HashLocationStrategy;
|
||||
|
||||
beforeEach(() => {
|
||||
locationStrategy =
|
||||
TestBed.configureTestingModule({imports: [AppModule]}).get(LocationStrategy);
|
||||
});
|
||||
|
||||
it('hash_location_strategy example works',
|
||||
() => { expect(locationStrategy.prepareExternalUrl('app/foo')).toBe('#app/foo'); });
|
||||
});
|
||||
}
|
30
modules/@angular/examples/common/location/ts/module.ts
Normal file
30
modules/@angular/examples/common/location/ts/module.ts
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
import {APP_BASE_HREF} from '@angular/common';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
import {HashLocationComponent} from './hash_location_component';
|
||||
import {PathLocationComponent} from './path_location_component';
|
||||
|
||||
@Component({
|
||||
selector: 'example-app',
|
||||
template: `<hash-location></hash-location><path-location></path-location>`
|
||||
})
|
||||
export class ExampleAppComponent {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [ExampleAppComponent, PathLocationComponent, HashLocationComponent],
|
||||
providers: [{provide: APP_BASE_HREF, useValue: '/'}],
|
||||
imports: [BrowserModule],
|
||||
bootstrap: [ExampleAppComponent]
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
// #docregion LocationComponent
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'path-location',
|
||||
providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}],
|
||||
template: `
|
||||
<h1>PathLocationStrategy</h1>
|
||||
Current URL is: <code>{{location.path()}}</code><br>
|
||||
Normalize: <code>/foo/bar/</code> is: <code>{{location.normalize('foo/bar')}}</code><br>
|
||||
`
|
||||
})
|
||||
export class PathLocationComponent {
|
||||
location: Location;
|
||||
constructor(location: Location) { this.location = location; }
|
||||
}
|
||||
// #enddocregion
|
Reference in New Issue
Block a user