亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 components.ts 文件中使用 KeyValuePipe?

如何在 components.ts 文件中使用 KeyValuePipe?

揚帆大魚 2021-11-04 17:51:38
是否可以在 ts 文件中而不是在 html 中使用 KeyValuePipe?如果是的話,有人可以告訴我怎么做嗎?這就是我現在擁有的,但顯然我不能像這樣使用管道。let item of this.entityDetails | keyvalue{            let properties:PropertyBase<any>[]=[                new TextboxProperty({                    key: item.key,                    label: item.key,                    value: item.value,                    required: false,                }),                ];        }
查看完整描述

3 回答

?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

你當然可以。你只需要像任何服務一樣導入它并注入它。你從@angular/common.


import { KeyValuePipe } from "@angular/common";


constructor(private keyValuePipe: KeyValuePipe) {


    const transformed = this.keyValuePipe.transform(this.entityDetails);


    for (let item of transformed) {

      let properties: PropertyBase<any>[] = [

        new TextboxProperty({

          key: item.key,

          label: item.key,

          value: item.value,

          required: false

        })

      ];

    }

  }


查看完整回答
反對 回復 2021-11-04
?
慕斯王

TA貢獻1864條經驗 獲得超2個贊

是的,您可以在 ts 文件中使用管道。


 constructor(public dataformatpipe: DateFormatPipe){}


ngOnInt(){}


  formatData(date) {

    return this.dataformatpipe.transform(date);

   }

html文件


 <span class="value-data">{{formatData(item.startData)}}</span>


查看完整回答
反對 回復 2021-11-04
?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

在那里編寫一個自定義管道,您可以在 ts 文件中寫入,以便您可以轉換,從父級作為管道輸入傳遞并使用您的管道 ts 文件以供參考,請訪問此處 https://alligator.io/angular/custom-pipes-angular/


查看完整回答
反對 回復 2021-11-04
  • 3 回答
  • 0 關注
  • 335 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號