- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想将我的 [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     ;eq',
'notEquivales' = '\u2262     ;nev',
'implies' = '\u21d2     ;im',
'not' = '\u00AC     ;not',
'conjunction' = '\u22c0     ;an',
'disjunction' = '\u22c1     ;or',
'emptySet' = '\u2205     ;es',
'union' = '\u222A     ;un',
'intersection' = '\u2229     ;in',
'powerSet' = '\u2118     ;ps',
'gets' = '\u2254     ;=',
'genericQuantifier' = '\u2605     ;st',
'atLeast' = '\u2264     ;ge',
'atMost' = '\u2265     ;le',
'elementOf' = '\u2208     ;el',
'notElementOf' = '\u2209     ;nel',
'properSuperset' = '\u2283     ;pp',
'superset' = '\u2287     ;sp',
'notProperSubset' = '\u2284     ;npb',
'notSubset' = '\u2288     ;nsb',
'notProperSuperset' = '\u2285     ;npp',
'notSuperset' = '\u2289     ;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();
}
所以目前我的网页显示了一个如下所示的下拉菜单:
这很好,但是当我单击其中一个选项并将其输入到编辑器中时,它会将快捷键代码保留在右侧,而实际上我只想在单击时将 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/
我正在尝试使用[选定]和[ngValue]来设置表单中包含对象的选择标记的默认值。但出于某种原因,它们似乎无法相提并论。。示例代码:。这段代码最终只显示空白作为缺省值。如果删除[ngValue],它就
如何避免表单输出中出现空白选项? Real Fake
使用 [ngValue] 从选择返回的值是索引和值的串联 如果我用这个 {{type.display}} 然后我用它来获取所选选项的值 selectType (e) { this.
我试图在填充选择时设置一个初始值,数据来自 rest 并加载到组件中。在 之后未设置/更新初始值 获取列表以填充选择: ... ngOnInit():any { this.crudService.ge
这是我正在尝试做的事情:我想要一个选择列表绑定(bind)到一个带有 ngValue 的对象数组,但是第一个选项需要是一个带有 null 的“无”选项。值(value)。 型号: this.manag
我最近才发现 SELECT 的 OPTION 部分的 value 属性有一个替代方案,即 ngValue。文档确实缺少关于此的文档(我只能找到:https://angular.io/docs/ts/l
这个问题的风格在发布之前已经在 Angular2 的各种版本中被问过很多次。但是,我还没有在此处的 plunk 中找到任何会产生所需行为(缺乏我想避免的解决方法)的东西:Select Object P
我正在尝试使用 [selected] 和 [ngValue] 设置包含表单中对象的选择标签的默认值。但出于某种原因,它们似乎不相容。 示例代码: {{store.name}
我想将我的 [ngValue] 属性绑定(bind)到一个删除了最后 4 个字符的字符串,事先使用 ngFor 执行此操作的最佳方法是什么?这是代码: 这是我从
我正在尝试在 Angular 5 中实现 select,但我不断得到这个 我已经尝试过很多 StackOverflow 问题,唯一的区别是 - 我的组件位于应用程序的另一个模块中,该模块最终注入(in
今天我意识到 Angular 5 中响应式表单的意外(对我来说)行为。服务器从应用程序接收到一个字符串,其值为“null”而不是 null 值,这正是我想要的。 我做了以下测试: https://st
我正在使用 angular 5,但出现了控制台错误: Can't bind to 'ngValue' since it isn't a known property of 'mat-option' 我
我正在使用 [(ngModel)]作为一个整体。当我从头开始时,这很好用,但在编辑模式下使用时就不行了。因此,例如当我分配 ngModel 时通过其他一些功能,选择下拉列表的 View 不会更新。 这
我是一名优秀的程序员,十分优秀!