小编Pra*_*ran的帖子

角度动态字符串绑定

我正在尝试实现一种标准,其中所有字符串文件都来自单独的常量文件。一切都很好,但是当字符串中的动态值出现时,会遇到困难。请帮助我如何使用常量。

常数

export enum testPageConstants {
   SuccessMessage = 'You have created {{count}} users'
}
Run Code Online (Sandbox Code Playgroud)

userPage.ts

export class UserPage {
   import {testPageConstants} from '...';
   constantUIBind: typeof testPageConstants;
   count = 10;

   constructor() {
       this.constantUIBind = testPageConstants;
   }
}
Run Code Online (Sandbox Code Playgroud)

userPage.html

<p> {{constantUIBind.SuccessMessage}}</p>
Run Code Online (Sandbox Code Playgroud)

输出:在HTML中,收到的消息类似于“您已经创建了{{count}}个用户”,但我希望收到的消息类似于“您已经创建了10个用户”

angular

6
推荐指数
1
解决办法
90
查看次数

标签 统计

angular ×1