Angular2拆分字符串(竖线?) [英] Angular2 split string (pipe?)
本文介绍了Angular2拆分字符串(竖线?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以以某种方式使用类似于{{mystr | split(last) }}
的东西?
Is it possible to use something similar to {{mystr | split(last) }}
somehow?
我希望已经有一个烟斗.
I'm hoping there is a pipe included already.
推荐答案
为此您需要一个自定义管道.您可以通过以下方式实现:
You need a custom pipe for this. You could implement this this way:
@Pipe({
name: 'split'
})
export class SplitPipe implements PipeTransform {
transform(val:string, params:string[]):string[] {
return val.split(params[0]);
}
}
并像这样使用它:
{{mystr | split:last }}
其中last
是组件的与分隔符相对应的属性.
where last
is a property of your component that corresponds to the separator.
这篇关于Angular2拆分字符串(竖线?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文