List with pulldown options

I am trying to implement a drop-down list with bullets using Angular 2, JavaScript, and CSS. Although I have managed to create the drop-down list, I am facing difficulty in adding bullets to the list items.

Unfortunately, I have found that jQuery and Bootstrap are not suitable for achieving this functionality. Can anyone provide any suggestions or solutions?

Below is the code snippet I have been working on:

 dropdownList.component.ts

 import { Component} from '@angular/core';
 import{FormsModule } from '@angular/forms';
 import {Option} from './option';

 @Component({
  selector: 'app-dropdown',
  templateUrl: './dropdown.component.html',
  styleUrls: ['./dropdown.component.css']
})
export class DropdownComponent {

  selectedItem: Option = new Option(1,'../../assets/blue2.png', 'option1');

  options = [
    new Option(1,'../../assets/blue2.png', 'option1'),
    new Option(2, 'option2'),
    new Option(3, 'option3'),
    new Option(4, 'option4')
  ];

 // Option.ts


export class Option{


constructor(public id?: number, public img?: string, public name?: 
string) {
  }
}

// component.html:


<select class="dropdown" id="style">
<option *ngFor="let Option of options" value={{Option.id}} 
class="dropdownList">{{Option.name}}{{Option.img}}

</option>
</select>

Answer №1

CSS has the power to transform any element into something completely different. I recently created a straightforward dropdown menu with only essential features. To fully develop this dropdown, you will need to incorporate ngModel and label/value dropdown items. However, I believe it already encompasses what you described.

import { Component } from '@angular/core'

@Component({
  selector: 'demo-dropdown',
  template: `
    <div class="ui-dropdown">
      <label class="ui-dropdown-label">{{selectedItem}}</label>
      <span class="ui-dropdown-button" (click)="showList = !showList">﹀</span>
      <ul class="ui-dropdown-list" [class.active]="showList">
        <li *ngFor="let item of items" (click)="onItemSelected($event)">{{item}}</li>
      </ul>
    </div>
  `,
  styles: [`
    *{
       box-sizing: border-box; 
    }
    .ui-dropdown{
      background: #fff;
      border: 1px solid black;
      border-radius: 3px;
      display: inline-flex;
      flex-wrap: wrap;
      padding: 0;
      user-select: none;
      width: 250px;
    }
    .ui-dropdown-label{
      flex: 1 1 0;
      padding: 0.2em 0.5em;
    }
    .ui-dropdown-button{
      border-left: 1px solid black;
      cursor: pointer;
      flex: 0 0 20px;
      padding-top: 0.2em 0.2;
    }
    .ui-dropdown-list{
      background: #fff;
      border: 1px solid black;
      border-radius: 3px;
      display: none;
      flex: 0 0 100%;
      margin: 0;
      margin-top: 25px;
      padding: 0;
      position: absolute;
      width: 250px;
    }
    .ui-dropdown-list.active{
      display: block;
    }
    .ui-dropdown-list>li{
      cursor: pointer;
      list-style: none;
    }
    .ui-dropdown-list>li::before{
      content: '.';
    }
    .ui-dropdown-list>li:hover{
      background: #eee;
    }
  `]
})
export class DemoDropdown{
  showList:boolean = false;
  selectedItem:string = null;
  items: OptionItem[] = ["option 1","option 2"];

  constructor() { }

  onItemSelected(e){
    this.selectedItem = e.target.innerText;
    this.showList = false;
  }
}

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

Error Unhandled in Node.js Application

I have encountered an issue in my NodeJS application where I have unhandled code in the data layer connecting to the database. I deliberately generate an error in the code but do not catch it. Here is an example: AdminRoleData.prototype.getRoleByRoleId = ...

Error encountered: EPERM - Unable to perform operation on Windows system

Recently, I executed the following command: npm config set prefix /usr/local After executing this command, I encountered an issue when attempting to run any npm commands on Windows OS. The error message displayed was as follows: Error: EPERM: operation ...

What is the best way to incorporate async/await in a useEffect hook in a React Native application?

Upon executing useEffect, my objective is to retrieve the token from AsyncStorage, fetch the data value using the axios.post('/auth/me') endpoint, and trigger the KAKAOLOG_IN_REQUEST action through dispatch. After verifying that the data value i ...

Is it possible for a jQuery ajaxSuccess function to detect an AJAX event in a separate JavaScript file? If it is, what steps am I missing?

I've been attempting to initiate a function following an ajax event. I have been informed that despite the ajax event occurring in a different file (on the same server, if that makes a difference) and that the file is javascript, not jquery, "Ajaxsucc ...

Retrieve the data from a JSON file using Angular 4

I have a JSON data structure that looks like this: [{"id": "ARMpalmerillas07", "type": "GreenHouse","act_OpenVentanaCen": {"type": "float", "value": 0, "metadata": {"accuracy": {"type": "Float", "value": "07/02/2018 13:08 : 43 "}}}, "act_OpenVentanaLatNS" ...

Encountering an error in Vue.js where a "cannot read property of undefined" message is displayed when attempting to use v

While attempting to use v-model on an array item's property, I encountered the error message "[Vue warn]: Error in render function: 'TypeError: Cannot read property 'viewFood' of undefined' when loading the page. This resulted in a ...

react component not displaying image

I must admit, this might be a silly question but I'm just starting out in web development. My goal is to create a clickable image component that redirects to another page on the website. However, despite not encountering any errors, the image is not ...

Pixel information from previous canvas remains intact post resizing

I have crafted a canvas and loaded pixel data at specific locations using the following code snippet. let maskCanvas = document.createElement("canvas"); let patchWidth = 30; let patchHeight = 30; let scale = 3; maskCanvas.setAttribute("class", "mask"); ...

Stopping a Bootstrap Modal Closure When Validation Errors are Present

I'm dealing with a bootstrap model within a .NET MVC5 app. Although my client-side validation is functioning properly (using jquery unobtrusive in MVC), I have encountered an issue where the modal keeps closing even when there are errors present. How ...

Is it possible to use one table as a background and place another table on top of it?

Currently, I am designing an email template and due to restrictions, I can only use tables. I am looking for a solution to meet my requirements using tables. Since all the content is dynamically generated via an RSS feed, images cannot be used in this ca ...

"I am facing an issue where the button does not appear centered after using jQuery

I can't help but notice that when applying CSS directly, my buttons end up centered horizontally. Yet, when I insert the same code using append(), the buttons seem to align towards one side instead. Here is the HTML/CSS code snippet: <div style=" ...

Is it possible to determine the status of several angular components at once?

After following a tutorial to create a Tic-Tac-Toe app, I am now attempting to enhance its functionality independently. The draw condition is the current obstacle that I am facing. Each square in the tic-tac-toe grid is represented by its own Angular Comp ...

Alignment troubles persist with text formatting

The alignment of the link at the bottom of the page seems to be causing an issue. <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="cssforwebsite.css"/> <link href="https://fonts.googleapis.com/c ...

Turning Node.js timestamp into MySQL format

Currently, I am using Node (Express.js) to update a MySQL database with the current date. While it is functional, my code seems to be repetitive. let newDate = new Date(); let yearNow = newDate.getFullYear(); let monthNow = newDate.getMonth(); let dayNow ...

No matter the way I input the URL in the AJAX call, the response always comes back as successful

I ran into an issue with my ajax request. It was supposed to be a GET request that returned some data, but no matter how I configured the URL, it always gave a success response even when it didn't actually succeed. var id = 5; $.ajax({ type: ...

Mastering the art of constantly monitoring data changes in a Firebase real-time database using Vue.js

I am currently utilizing vue.js version 2 in CDN mode. I have designed 2 vue components - one that pushes data to a database and another that displays it. Here is the code snippet: firebase.database().ref().on('value', function (data) { c ...

How to Utilize Output() and EventEmitter() for Value Transmission in Angular Application

Last week I was successfully able to implement Output() and EventEmitter() in my Angular app. However, today I am facing a new challenge while trying to apply the same concept in a different scenario. I'm not sure what I might be overlooking. Firstly ...

JavaScript function overriding allows a subclass to provide a specific implementation of

I have a JavaScript file with two methods: var DBProcessing = function() { console.log("ok") ... } var DBProcessing = function(str) { console.log(str); ... } When calling DBProcessing(), I am only getting an output of undefined. Is there a way to expli ...

BlurDataURL for Data URLs in Next.js

NextJS 11 brings the exciting feature of using the Image component with a blur placeholder. To utilize this with dynamic images, we need to make use of the blurDataURL, which is a Data URL. I am interested in taking my original image and resizing it to a ...

The JavaScript-rendered HTML button is unresponsive

I have a JavaScript function that controls the display of a popup window based on its visibility. The function used to work perfectly, with the close button effectively hiding the window when clicked. However, after making some changes to the code, the clo ...