TypeScript + AngularJS 1:如何使用select指令连接枚举? [英] TypeScript + AngularJS 1: How to connect enum with select directive?
问题描述
我从HTML中加入SELECT的问题。我的枚举结构如下所示:
I am having an issue with joining enum with SELECT from HTML. My enum structure looks as follows:
enum Color {
Green,
Red,
Blue
}
我想以某种方式将此枚举绑定到html选择标签,使用角。任何想法?
I would like to somehow bind this enum to the html select tag, using angular. Any ideas?
感谢
uksz
Thanks
uksz
推荐答案
p>当您的枚举被编译为JavaScript时,它将成为以下对象。您可以看到等效的JavaScript
When your enum is compiled to JavaScript, it will become the following object. You can see the equivalent JavaScript here at TypeScript playground.
{
0: "Green"
1: "Red"
2: "Blue"
"Blue": 2
"Green": 0
"Red": 1
}
现在,您可以看到,如果要绑定一个< select>
,您将获得数字和非数字项目。假设您只想在列表中显示非数字项目,则需要对其进行过滤。
Now as you can see, if you were to bind this with a <select>
you will get both the numeric and non-numeric items. Assuming you only want non numeric items to show up in the list, you will need to filter it.
这篇关于TypeScript + AngularJS 1:如何使用select指令连接枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!