gpt4 book ai didi

Angular:删除 [ngValue] 绑定(bind)字符串的最后 4 个字符

转载 作者:搜寻专家 更新时间:2023-10-30 21:58:40 25 4
gpt4 key购买 nike

我想将我的 [ngValue] 属性绑定(bind)到一个删除了最后 4 个字符的字符串,事先使用 ngFor 执行此操作的最佳方法是什么?这是代码:

<select
id="symbolInLineSelector"
(change)="insertSymbol($event.target.value)"
class="ql-size"
title="symbolSelect">
<option
*ngFor="let symbol of keys(symbols)"
[ngValue]="symbol"
[innerHtml]="symbols[symbol]">
</option>
</select>

这是我从中提取的模型以及我如何在 typescript 中使用它:

型号

export enum Symbols {
'equivales' = '\u2261 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;eq',
'notEquivales' = '\u2262 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;nev',
'implies' = '\u21d2 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;im',
'not' = '\u00AC &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;not',
'conjunction' = '\u22c0 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;an',
'disjunction' = '\u22c1 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;or',
'emptySet' = '\u2205 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;es',
'union' = '\u222A &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;un',
'intersection' = '\u2229 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;in',
'powerSet' = '\u2118 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;ps',
'gets' = '\u2254 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;=',
'genericQuantifier' = '\u2605 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;st',
'atLeast' = '\u2264 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;ge',
'atMost' = '\u2265 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;le',
'elementOf' = '\u2208 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;el',
'notElementOf' = '\u2209 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;nel',
'properSuperset' = '\u2283 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;pp',
'superset' = '\u2287 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;sp',
'notProperSubset' = '\u2284 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;npb',
'notSubset' = '\u2288 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;nsb',
'notProperSuperset' = '\u2285 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;npp',
'notSuperset' = '\u2289 &nbsp; &nbsp; &nbsp; &nbsp; &thinsp; &thinsp; ;nsp'
}

typescript

import {Symbols} from '../../model/symbols';

keys = Object.keys;
symbols = Symbols;

insertSymbol(selectedVal) {
this.editorInstance.insertText(this.previousEditorSelection, selectedVal.splice(0,-4));
this.editorInstance.setSelection(this.previousEditorSelection.index + selectedVal.length + 1);
this.previousEditorSelection = this.editorInstance.getSelection();
}

所以目前我的网页显示了一个如下所示的下拉菜单:

enter image description here

这很好,但是当我单击其中一个选项并将其输入到编辑器中时,它会将快捷键代码保留在右侧,而实际上我只想在单击时将 unicode 字符插入到编辑器中。有没有办法在 [ngValue] 中拼接字符串,以便下拉列表显示所有信息,但插入会删除最后 4 个字符?正如您在上面看到的那样,我已经尝试直接在 ngValue 和函数调用中拼接,但都没有用。

最佳答案

使用 slice pipe .

<select
id="symbolInLineSelector"
(change)="insertSymbol($event.target.value)"
class="ql-size"
title="symbolSelect">
<option
*ngFor="let symbol of keys(symbols)"
[ngValue]="symbol | slice:0:-4"
[innerHtml]="symbols[symbol]">
</option>
</select>

关于Angular:删除 [ngValue] 绑定(bind)字符串的最后 4 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49799409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com