BREAKING CHANGE:
Instead of configuring pipes via a Pipes object, now you can configure them by providing the pipes property to the View decorator.
@Pipe({
name: 'double'
})
class DoublePipe {
transform(value, args) { return value * 2; }
}
@View({
template: '{{ 10 | double}}'
pipes: [DoublePipe]
})
class CustomComponent {}
Closes #3572
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import {isString, StringWrapper, CONST, isBlank} from 'angular2/src/facade/lang';
|
|
import {Injectable} from 'angular2/di';
|
|
|
|
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
|
|
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
|
|
|
|
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
|
|
|
/**
|
|
* Implements lowercase transforms to text.
|
|
*
|
|
* # Example
|
|
*
|
|
* In this example we transform the user text lowercase.
|
|
*
|
|
* ```
|
|
* @Component({
|
|
* selector: "username-cmp"
|
|
* })
|
|
* @View({
|
|
* template: "Username: {{ user | lowercase }}"
|
|
* })
|
|
* class Username {
|
|
* user:string;
|
|
* }
|
|
*
|
|
* ```
|
|
*/
|
|
@CONST()
|
|
@Pipe({name: 'lowercase'})
|
|
@Injectable()
|
|
export class LowerCasePipe extends BasePipeTransform {
|
|
transform(value: string, args: List<any> = null): string {
|
|
if (isBlank(value)) return value;
|
|
if (!isString(value)) {
|
|
throw new InvalidPipeArgumentException(LowerCasePipe, value);
|
|
}
|
|
return StringWrapper.toLowerCase(value);
|
|
}
|
|
}
|