angular - 如何用角度格式化密钥?
解决方案
由于key
将是 的固定值0 <= key < 12
,因此最快的方法是将符号列表(?)定义为数组(可能在外部文件中,例如config.ts)。
配置文件
export const NOTATIONS = [
'C',
'C♯/D♭',
'D',
'D♯/E♭',
'E',
'F',
'F♯/G♭',
'G',
'G♯/A♭',
'A',
'A♯/B♭',
'B'
];
资料来源:维基
并在组件中使用
控制器
import { Component } from '@angular/core';
import { NOTATIONS } from './config';
export class AppComponent {
notations = NOTATIONS;
...
}
模板
<div class="key-note">{{ notations[trackFeature.key] || 'Key unavailable' }}</div>
推荐阅读
- excel - 如何将多行的同一行中的值相加(Excel)
- jquery-ui - 如何在故事书中安装 Jquery-ui?
- django - RESTful API 按过滤器列表过滤数据
- oracle-apex - Oracle Apex 问题跟踪器系统-演示/示例项目
- sql - 带时间添加计算的条件选择
- junit5 - Selenium Jupiter 中多浏览器测试执行的标准方法
- asp.net-mvc - 使特定值需要 @Html.TextBoxFor
- javascript - React 组件 - 在未渲染时也继续工作
- sapui5 - 执行触发器时 SAP DBTech JDBC 的问题
- asp.net-core - appsetting中JwtIssuerOptions有什么用?