2015-06-22 17:11:55 -07:00
|
|
|
import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang';
|
2015-06-26 00:22:06 +04:30
|
|
|
import {Pipe, PipeFactory} from './pipe';
|
|
|
|
import {ChangeDetectorRef} from '../change_detector_ref';
|
2015-05-14 10:14:26 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements uppercase transforms to text.
|
|
|
|
*
|
|
|
|
* # Example
|
|
|
|
*
|
|
|
|
* In this example we transform the user text uppercase.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component({
|
|
|
|
* selector: "username-cmp"
|
|
|
|
* })
|
|
|
|
* @View({
|
2015-05-18 02:58:13 -07:00
|
|
|
* template: "Username: {{ user | uppercase }}"
|
2015-05-14 10:14:26 -07:00
|
|
|
* })
|
|
|
|
* class Username {
|
2015-05-18 02:58:13 -07:00
|
|
|
* user:string;
|
2015-05-14 10:14:26 -07:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*/
|
2015-06-18 15:40:12 -07:00
|
|
|
export class UpperCasePipe implements Pipe {
|
2015-06-16 08:47:24 +02:00
|
|
|
_latestValue: string = null;
|
|
|
|
|
2015-05-14 10:14:26 -07:00
|
|
|
supports(str): boolean { return isString(str); }
|
|
|
|
|
|
|
|
onDestroy(): void { this._latestValue = null; }
|
|
|
|
|
2015-06-26 00:22:06 +04:30
|
|
|
transform(value: string, args: List<any> = null): string {
|
2015-05-14 10:14:26 -07:00
|
|
|
if (this._latestValue !== value) {
|
|
|
|
this._latestValue = value;
|
|
|
|
return StringWrapper.toUpperCase(value);
|
|
|
|
} else {
|
|
|
|
return this._latestValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 17:11:55 -07:00
|
|
|
@CONST()
|
2015-06-26 00:22:06 +04:30
|
|
|
export class UpperCaseFactory implements PipeFactory {
|
2015-05-14 10:14:26 -07:00
|
|
|
supports(str): boolean { return isString(str); }
|
|
|
|
|
2015-06-26 00:22:06 +04:30
|
|
|
create(cdRef: ChangeDetectorRef): Pipe { return new UpperCasePipe(); }
|
2015-05-14 10:14:26 -07:00
|
|
|
}
|