Guide to setting an enum as the dataSource for a DevExtreme select dropdown box

I am seeking assistance in populating a select box with enum values that belong to a class property. Below is my HTML:

<div class="channel-visible">
        <div class="title">Visibility</div>
        <dx-select-box
        [(value)]="newChannel.visibility"
        [dataSource]="channelVisibility"
        >

        </dx-select-box>
    </div>

Here is the component code:

channelVisibility = EChannelVisibility;
newChannel = new Channel();

The enum type EChannelVisibility is a property of the Channel class. When attempting to implement it in the HTML above, I encounter the following error: https://i.sstatic.net/6RL0f.png

Answer №1

Here's a clever solution: you can create a string array based on your enum.

import { Component } from '@angular/core';

enum EChannelVisiblity {
  Up = 'UP',
  Down = 'DOWN',
  Left = 'LEFT',
  Right = 'RIGHT'
}

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  visibility!: any;
  channelVisibility!: any;

  constructor() {
    var arr = [];
    for (var i in EChannelVisiblity) {
      arr.push(i.toString());
    }

    this.channelVisibility = arr;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Replace interface with a string

Is it possible to override an interface with a string in TypeScript? Consider this example: type RankList = "Manager" | "Staff" interface EmployeeList { id: string, name: string, department: string, rank: "Staff&q ...

Error (2322) Occurs When TypeScript Class Implements Interface with Union Type Field

I'm having trouble with error code 2322 popping up unexpectedly. Could you please take a look at this code snippet for me? interface Fish { alive: string | boolean; } class FishClass implements Fish { alive = 'Yes' constructor() { ...

Modify the ngb-timepicker formatting to output a string instead of an object

I am currently working on modifying ngb-timepicker so that it returns a string instead of an object. Right now, it is returning the following format: { "hour": 13, "minute": 30 } However, I want it to return in this format: "13:30" This is the HTM ...

Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly. My current goal is to retrieve the values of the selecte ...

Angular's Recursive Issue with the Execution Order of RxJS Observables

I am currently experiencing an issue with the execution order of recursive RxJS Observables within an Angular application. Specifically, I have a service called RefreshReportService that handles the refreshing of reports. The refreshreport method is intend ...

Tips for effectively implementing React.usecallback

Looking for a way to rewrite the handleClick method using React.useCallback in a function called Parent, which is triggered by a button click event in React and TypeScript. function Parent () { const [isOpen, setIsOpen] = React.useState(false); ...

Using Angular to facilitate communication between administrators and students in Azure's webpubsub service; enabling messages to be sent in either

Currently, in my Angular project, I am developing a chat application using Azure Web PubSub. The main functionality is that an admin can send messages to a student, and vice versa. Admin to student: const apiUrl = ${environment.Negotiate_apiBaseUrl}/${con ...

How can I get rid of the table borders and set colors for every other row in the

How can I remove the border lines from a table and assign colors to alternate rows in the table? Follow this link for the code: https://stackblitz.com/angular/kooxxyvddeqb?file=app%2Ftable-sticky-columns-example.css Thank you in advance ...

Error with an Array of Objects in an Array when using Angular and Typescript

Our system has an array called "food/essen" with a total of 10 items. The food plan is made up of 8 objects from the "Food" array and includes an ID for the week number. An issue we are facing in our web application is that although it recognizes the 8 o ...

When a React component written in TypeScript attempts to access its state, the object becomes

Throughout my app, I've been consistently using a basic color class: const Color = { [...] cardBackground: '#f8f8f8', sidebarBackground: '#eeeeee', viewportBackground: '#D8D8D8', [...] } export defau ...

Encountering an issue while trying to install font-awesome in an Angular project

Encountering an error while trying to install font-awesome in angular npm install --save @fortawesome/fontawesome-free npm ERR! code UNKNOWN npm ERR! syscall rename npm ERR! path C:\Users\pratish.devangan\OneDrive - HCL Technologies Ltd&bso ...

Creating a complete fullstack application in Angular 2 starting from the basics

Can anyone suggest tutorials, whether they are free or paid, for building an Angular 2 full stack from scratch? I've come across various packages and generators, but I want to learn how to create my own structure. ...

Tips for enhancing parameters in TypeScript/Angular methods

I'm working with a function that has multiple parameters: public find( cadnum: string, pagesize: number, startid?: string ): Observable<any> { let url = ""; if (cadnum) { url+= "?cadnum=" + cadnum; } if ...

Any problems with TypeLite involving generics or Enums?

Would you believe I have a plethora of .Net libraries/classes that I want to create typescript definitions for? Typescript is truly amazing! I experimented with simple examples and it worked flawlessly. However, the hiccup I'm facing now is that a par ...

Error encountered when attempting to retrieve token from firebase for messaging

I am currently working on implementing web push notifications using Firebase. Unfortunately, when attempting to access messaging.getToken(), I encounter an error stating "messaging is undefined." Below is the code snippet I am utilizing: private messaging ...

Vue version 3 is encountering an issue with a module that does not have an exported member in the specified path of "../../node_modules/vue/dist/vue"

After I updated my npm packages, errors started popping up in some of the imports from the 'vue' module: TS2305: Module '"../../node_modules/vue/dist/vue"' has no exported member 'X' The X instances affected inclu ...

Submitting a Form with Request Body using Angular 2

I am struggling to figure out how to send a form to an API with the body. I have managed to hard code the body so far, but I really need to dynamically retrieve values from the form and send them as the body to the API. Can someone please guide me on how t ...

Vue.js: The $attrs and $listeners properties are both read-only

I attempted to construct my own component library using Vuetify, utilizing vue-cli vue create d-components. I registered my components through an install function that was exported in the main.ts file of my library like this: import Vue, { VueConstructor } ...

Angular TypeScript test checking file size with Jasmine

Seeking optimal method for testing File size during input type="file" change event. Currently, my test specification appears as follows: it('attach file with too large size', () => { const file: File = { name: 'filename', ...

The draggable container refuses to move despite implementation of Hammerjs and Angular

I have a situation in my angular app where cards (divs) can be dragged and relocated on desktop, but I'm trying to make it work on mobile using hammerjs. https://i.sstatic.net/9JtgPm.png Currently, I have implemented a (pan) event handler which is t ...