Images in a horizontal dropdown selection menu

Currently, I have a traditional select dropdown that is data-bound with Angular.

<select class="form-control" ng-model="category">
   <option value="work">Work</option>
   <option value="home">Home</option>
   <option value="practical">Practical</option>
   <option value="no">No category</option>
</select>

My goal is to transform the dropdown options into horizontal images rather than vertical text. Here is what I envision:

SELECT BUTTON

work image - home image - practical image

I have experimented with using display: inline-blocks, floats, and even contemplated using radio buttons based on a related Stack Overflow question. As I am in the process of learning Angular, I would prefer to avoid the use of JQuery. Thank you for your help.

Answer №1

There are constraints regarding how you can customize selects. Your options include choosing from among the various customizable select plugins available or creating your own solution, like this:

<div ng-app="app">
    <div ng-controller="ctrlr">
        <span ng-repeat="entry in categories">
            <img ng-click="setCategory(entry)" ng-src="{{entry.src}}">
        </span>
        <div>Selected = {{category}}</div>
    </div>
</div>

<script>
    angular.module('app', []);
    angular.module('app').controller('ctrlr', function ($scope) {
        $scope.categories = [
            {
                code: 'work',
                src: 'Work.png'
            },
            {
                code: 'home',
                src: 'Home.png'
            },
            {
                code: 'practical',
                src: 'Practical.png'
            },
            {
                code: 'no',
                src: 'No category.png'
            }
        ];

        $scope.setCategory = function (entry) {
            $scope.category = entry.code;
        }
    });
</script>

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

Discover a step-by-step guide on showcasing SVG graphs in Vue using exclusively the SVG graph link

Currently, the only resource I have is a link to an SVG file. When opened in a browser, this link will display an SVG graph. My goal is to display this SVG graph in a Vue application: Although I attempted to implement this in Vue, it was unsuccessful. A ...

Choose the option in real-time with Jquery

I'm currently developing a dynamic HTML for Select Option as seen below: item += "<td class='ddl' style='width:40%;'>"; item += "<select>" item += " <option id='list' name='selector' value=" + se ...

What are the benefits of using CSS to convert text to uppercase?

Today, I came across an intriguing observation. While browsing through code, I noticed that text was being transformed to uppercase using CSS instead of the common JavaScript method toUpperCase(). Surprisingly, this approach caused a test to fail. The test ...

Problem encountered when using the Mongoose find() method with the exec() function

Could you please clarify why the code snippet below is returning audiences instead of an empty array? return Audience.find() .exec((err, audiences) => { if (err) return errorHandler.handle('audienceService', err); return Promise.re ...

What is the best way to verify the presence of # in a URL?

Every now and then, due to caching issues, I find myself adding a # to my URL, like so: http://www.example.com/#lang=3201954253 My goal is to find and remove the #lang from the URL if it is present. ...

Searching for the desktop location using Node.js

As discussed in the Node.js - Find home directory in a platform-agnostic way question, we can locate the home directory using the following code: const homedir = require('os').homedir(); However, how can I locate the desktop folder in Windows r ...

Highlighting DOM elements that have recently been modified in Angular

Is there a simple way to change the style of an element when a bound property value changes, without storing a dedicated property in the component? The elements I want to highlight are input form elements: <tr field label="Lieu dépôt"> ...

Step-by-step guide on importing popper.js

While it may seem like a simple question, I am struggling to find the answer. How can I import popper.js that comes with Bootstrap 4 beta? I am using Bower and have successfully installed Bootstrap 4 beta. However, in the bower_components folder, there is ...

Can React-Select be utilized in the browser directly from the CDN?

Is it possible to utilize react-select directly in the browser without using bundlers nowadays? The most recent version that I could find which supports this is 2.1.2: How to import from React-Select CDN with React and Babel? In the past, they provided r ...

Switch out fontawesome icons for SVG icons

I'm looking to replace the Fontawesome icons on this template. The full HTML code is available here, but I only need to swap out one specific icon with an SVG. https://i.sstatic.net/k1DFZ.png <div class="col-md-4"> ...

Creating HTML tags using Kotlin

Looking to generate HTML using Kotlin in the browser, I experimented with the Kotlinx library. However, I found that it lacks support for callbacks like the following: div { onclick = { event -> window.alert("Kotlin!") } } Are there an ...

How to use Vue.js to automatically redirect to a URL when a button is clicked

I have created a button that, when clicked, should redirect to a URL passed in it. Below is the code snippet: <template> <button type="button" v-on:click="gotosite(modalDetails.final.product_url)">Buy</button> </template> <s ...

"Facing an issue with my handleChange function not getting triggered in MaterialUI. Can anyone

Why isn't my handleChange function being invoked with the TextField component from Material UI? Even though I can input values in the text fields, the component's state is not updating. Here is the Auth component: const Auth = () => { cons ...

Is there a way to use an Angular expression inside an HTML document to determine if a variable is a boolean type?

I'm working with an element in my HTML where I need to determine the type of a variable, specifically whether it's a boolean or not. <button process-indicator="{{typeof(button.processIndicator) === 'boolean' ? 'modalProcess&apo ...

Using moment.js to perform addition of time does not yield the desired outcome

Every time I try to ---- make changes ---- var someMoment = moment('6:30 PM', ["h:mm A"]); ---- end changes ---- someMoment.add(30, 'minutes') I am not getting any desired outcome. console.log(start); -- Moment {_isAMomentObject: ...

What methods can be used to replicate a network delay while conducting unit tests for an AngularJS controller?

I am currently utilizing the $httpBackend service within the ngMock module to emulate a GET request. The following is a sample controller code snippet sourced from the AngularJS documentation: // Example controller code function MyController($scope, $http ...

Utilize a single JavaScript script to handle numerous HTML forms within the same webpage

I am currently facing an issue with a page that contains multiple forms needing the same JavaScript code. This specific code is designed to add more input fields to the form, which it does successfully. However, the problem lies in the fact that it adds in ...

Converting the OpenCV GetPerspectiveTransform Matrix to a CSS Matrix: A Step-by-Step Guide

In my Python Open-CV project, I am using a matrix obtained from the library: M = cv2.getPerspectiveTransform(source_points, points) However, this matrix is quite different from the CSS Transform Matrix. Even though they have similar shapes, it seems that ...

Maintain the tab count in AngularJs navigation

As someone who is new to AngularJs, I am currently exploring the best approach for a tabController to remember the last clicked tab when transitioning to a new controller. Imagine having 3 tabs and clicking on tab 3; then navigating to a new controller and ...

center a horizontal line using StyledSheets in your project

After drawing a horizontal line, I noticed that it is positioned towards the left side of the screen. I am hesitant to increase its width. Are there any other methods to move it to the center? I attempted wrapping it with another view and using alignConten ...