我自定義管道縮短字符串不起作用。我已經將它包含在我的app.module聲明中,並將其導入到我的組件中。代碼如下。自定義角度4管道不工作
` import { Pipe, PipeTransform } from '@angular/core';
/*
Takes a string and replaces it with a shortend version based on the length you give it if its greater than 14 char for Example
someString = "hey whats up my name is Bob and im from Bob town"
{{value | shortString : length of new string}}
{{someString | shortString: 10}}
*/
@Pipe({name: 'shortString'})
export class shortString implements PipeTransform {
transform(value: any, length: number): string {
console.log('expected new string '+value.slice(0,length)+'...');
return (value.length()>14)?value.slice(0,length)+'...': value;
}
}`
它是如何不工作的工作plunker?它是否產生錯誤?或者只是不縮短價值? – DeborahK