我试图在angular2中创建一个小写的管道,然后我遇到了问题
syntax errors got ';'
应用程序/ lowercase.ts
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({ name: 'lowercase1'})
export class LowerCasePipe1 implements PipeTransform {
transform (value: string): string {
if (!value) return value;
if (typeof value !== 'string'){
throw new Error('Invalid pipe value: ', value);
}
return value.toLowerCase();
}
}
应用程序/ app.component.ts
import {Component} from '@angular/core';
import {LowerCasePipe1} from './lowercase';
@Component({
selector: 'app',
pipes: [LowerCasePipe1],
template: '<h1>{{"SAMPLE" | lowercase1 }} </h1>'
})
export class App {
console.info('lower case app')
}
应用程序/ index.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {App} from './app.component';
//
bootstrap(App)
以下是plunkr:http://plnkr.co/edit/coB5AGWvpihUvCnBtX9D?p=preview