2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-08-16 14:15:01 -04:00
|
|
|
import {Component, NgModule} from '@angular/core';
|
|
|
|
import {BrowserModule} from '@angular/platform-browser';
|
|
|
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
2015-11-02 18:46:59 -05:00
|
|
|
|
|
|
|
// #docregion SlicePipe_string
|
|
|
|
@Component({
|
|
|
|
selector: 'slice-string-example',
|
|
|
|
template: `<div>
|
|
|
|
<p>{{str}}[0:4]: '{{str | slice:0:4}}' - output is expected to be 'abcd'</p>
|
|
|
|
<p>{{str}}[4:0]: '{{str | slice:4:0}}' - output is expected to be ''</p>
|
|
|
|
<p>{{str}}[-4]: '{{str | slice:-4}}' - output is expected to be 'ghij'</p>
|
|
|
|
<p>{{str}}[-4:-2]: '{{str | slice:-4:-2}}' - output is expected to be 'gh'</p>
|
|
|
|
<p>{{str}}[-100]: '{{str | slice:-100}}' - output is expected to be 'abcdefghij'</p>
|
|
|
|
<p>{{str}}[100]: '{{str | slice:100}}' - output is expected to be ''</p>
|
|
|
|
</div>`
|
|
|
|
})
|
|
|
|
export class SlicePipeStringExample {
|
|
|
|
str: string = 'abcdefghij';
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
// #docregion SlicePipe_list
|
|
|
|
@Component({
|
|
|
|
selector: 'slice-list-example',
|
|
|
|
template: `<div>
|
2016-04-25 22:52:24 -04:00
|
|
|
<li *ngFor="let i of collection | slice:1:3">{{i}}</li>
|
2015-11-02 18:46:59 -05:00
|
|
|
</div>`
|
|
|
|
})
|
|
|
|
export class SlicePipeListExample {
|
|
|
|
collection: string[] = ['a', 'b', 'c', 'd'];
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'example-app',
|
2015-11-23 19:02:19 -05:00
|
|
|
template: `
|
2015-11-02 18:46:59 -05:00
|
|
|
<h1>SlicePipe Examples</h1>
|
|
|
|
<slice-list-example></slice-list-example>
|
|
|
|
<slice-string-example></slice-string-example>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class AppCmp {
|
|
|
|
}
|
|
|
|
|
2016-08-16 14:15:01 -04:00
|
|
|
@NgModule({imports: [BrowserModule], bootstrap: [AppCmp]})
|
|
|
|
class AppModule {
|
2015-11-02 18:46:59 -05:00
|
|
|
}
|
2016-08-16 14:15:01 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
platformBrowserDynamic().bootstrapModule(AppModule);
|
2016-08-19 15:51:01 -04:00
|
|
|
}
|