【问题标题】:Angular2 trying to slice string object using SlicePipe in templateAngular2 尝试在模板中使用 SlicePipe 对字符串对象进行切片
【发布时间】:2016-09-30 14:47:52
【问题描述】:

参考:https://angular.io/docs/js/latest/api/common/SlicePipe-class.html。尝试对字符串对象的前 20 个字符进行切片。

试过了:

<p>{{item.description | slice:0:20}}...</p>

和

<p>{{item.description}}[0:20]: '{{item.description | slice:0:20}}'</p>

这里的 item.description 是 String 类型

export class Details {
  description: string; 
}

@Component({
  selector: 'editor'
})
export class AppComponent implements OnInit {
  item: details = <Details>{};
}

注意:我在模板中使用 {{item.description}} 获得了描述的价值,但是当我切片时它说

管道“SlicePipe”的参数“未定义”无效

任何帮助都会很棒。

【问题讨论】:

    标签: angular angular2-template angular2-pipe


    【解决方案1】:

    这似乎是一个已知问题https://github.com/angular/angular/pull/7152

    最近好像修好了,还没发货。

    【讨论】:

    • 有没有其他方法可以对字符串进行切片。我正在尝试执行段落阅读更多功能(可以在 css 上完成)我正在尝试 angular2。有关 Angular2 稳定版本的任何信息。
    • 您可以创建自己的切片管道。上面的链接包含包含修复的源代码(它只是几行代码)。它只是尚未包含在已发布的 Angular 版本中。
    猜你喜欢
    • 2020-12-03
    • 2012-07-13
    • 2021-03-12
    • 2014-07-08
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2012-01-20
    • 2012-11-20
    相关资源
    最近更新 更多