AngularJS: Issue with Select Click Trigger Not Fired

I am puzzled as to why this code isn't working on Chrome but works perfectly fine on FireFox

SelectModel

selectModel: [
                        {
                            value: "asc", htmlText : "A-Z", selected: ""
                        },
                        {
                            value: "desc", htmlText : "Z-A", selected: ""
                        },
                        {
                            value: "startDate", htmlText : "Date", selected: ""
                        }
                    ]

html

<option ng-click="sortContent(item)" ng-selected="item.selected" class="sort_option" value="{{item.value}}" ng-repeat="item in selectModel">
        {{item.htmlText}}
</option>

========================================================================= Directive:

return {
    restrict: 'E',
    replace: true,
    scope: {
    },
    link: function (scope, element, attributes) {
    scope.sortContent =  function(item_){
            console.info("???????????????????????????????????????????????????????????????????????????????")
        }
}

The issue lies in the fact that the function doesn't seem to be triggering on Google Chrome

You can test it out here: Runs smoothly on FireFox, but not on Chrome _ https://jsfiddle.net/bt6hmbvf/1/

Answer №1

The solution is straightforward. The reason why Ng-click doesn't function within the <option> element is because it is designed to work within the <select> element. I encountered a similar issue just a couple of days ago.

You can find my updated version with the fix at this link.

Answer №2

Try using ng-app ="myApp" to solve the issue mentioned in your provided fiddle

Here is the example with an error: http://jsfiddle.net/kevalbhatt18/bt6hmbvf/

Check out this demo instead: https://jsfiddle.net/kevalbhatt18/bt6hmbvf/4/

<div ng-app ="myApp" ng-controller="MyCtrl">
        {{d}}
</div>


Edit:

Take a look at this example: https://jsfiddle.net/hk0tn0co/3/

In your updated fiddle, you need to add ng-change to the select element and also include ng-model as it is required when using ng-change

<div ng-app="myApp" ng-controller="MyCtrl">
    <sampdir>
        {{msgClick}}
        <select ng-change="sortContent(item.value)" ng-model="item.value">
           <option  ng-selected="item.value" class="sort_option" value="{{item.value}}" ng-repeat="item in selectModel" >
                        {{item.htmlText}}
                    </option>
                </select>        
    </sampdir>
</div>

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

Methods for showcasing Array values by utilizing a timeout function

In the array below, I have a list of values: var pages = [{“page”:”url1”,”time”:”20”}, {"page":"url2”,”time”:”25”}, {"page":"url3”,”time”:”10”}, {"page":"url4”,,”time”:”12”}, {"page":"url5”, ...

A DOM-injected element will not initiate its own directive

My <ul> has ng-repeat directive. Within it, each "li" contains a <li directive> directive. The array (A) used by ng-repeat contains comments. When a user adds a new comment, I want it to be displayed first. To achieve this, I create a separate ...

angular click triggers the following content

How can I make the following content appear when clicked? I have a list of content that displays up to 20 items, but I want to show the rest when clicked. I have created the nextMovieList method for this purpose. import { Component, OnInit } from ' ...

I am trying to understand why my React component's render function is being called twice - first without any data and then again with data, resulting in a

I am facing an issue with my TreeNav component, where the data is fetched from an API call. I have set up the reducer, action, and promise correctly, but when I try to map over the data in the component render function, I get an error saying "Uncaught Type ...

After executing grunt serve, Bower issues a warning for jquery stating "not injected"

Recently, I had to clone a project and rebuild bower packages. It seems that jQuery has been updated, causing a warning to appear: Warning: Please check the "app/bower_components/jquery" folder for the necessary file and manually include it in your ...

Encountering HTML content error when attempting to log in with REST API through Express on Postman

I'm currently in the process of developing a basic login API using Node.js and Express. However, I've encountered an error when testing with Postman: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

Recording the screen with electron and utilizing the angularJS framework

I've been exploring the implementation of the electron recording method into my electron and angularJS desktop application. Since I am using angularJS to maintain services, controllers, and views, I have a button in one of my views (HTML file) that i ...

Tips for adjusting the size of an SVG using percentages

I have multiple tables with data in them, each sized using percentage and resizable. I want to add SVG images to each table without affecting the table size. When I tried setting the sizing like this: <svg xmlns="http://www.w3.org/2000/svg" xml:space=" ...

What is the best way to populate a dropdown with a specific value by retrieving the ID from the database?

Here is an example of code that displays a dropdown list using ng-repeat. When editing an entity, it may be necessary to show a specific value already selected instead of displaying the entire list. You can use the selected keyword to achieve this. What ...

Connect the <div> element to the Angular controller's element

We are faced with a rather intricate model within an AngularJS controller: function controller($scope) { $scope.model = { childmodel1: { childmodel2: { property1: 'abc', property2: 3, ...

Retrieving the text or value of an ASP.NET label using JavaScript

One of my challenges is transferring a string of data from C# to JavaScript in ASP web forms. My plan involves setting the data as a text for an ASP label in C#, then extracting the label's text by ID in JS. This is the C# code (ascx.cs file): L ...

Instructions for deleting a class from the body with jQuery while incorporating AngularJS

When using jQuery $(document).ready(function() { $("#pid1").removeClass("login_page"); }); HTML <body class="login_page" id="pid1" ng-app="myApp" ng-controller="myCtrl"> On the main page, a class is removed, but on the login page I want to ...

Immersive bootstrap 4 card featuring dynamic highcharts

I am faced with the challenge of making highcharts charts adjust their height when displayed in full screen mode within bootstrap cards. Even though I received assistance from "daniel_s" in creating an example for panels, the transition to cards and additi ...

Enhancing React components with dynamic background colors for unique elements

I am encountering an issue while using a map in my code. Specifically, I want to set the background of a particular element within the map. The element I am referring to is "item .title". I aim for this element to have a background color like this: https:/ ...

Using AngularJS promises within a loop

I have been working on a code snippet that iterates through the list of reports, modifies each one's name, and performs an update operation. Everything seemed to be in order when there was only one report in the list. However, things went haywire when ...

How can I create an HTML select dropdown menu with a maximum height of 100% and a dynamic size?

The dropdown menu I created using an HTML select tag contains a total of 152 options. However, the large number of options causes some of them to be out of view on most monitors when the size is set to 152. I attempted to limit the number of displayed opti ...

Issues with Chrome when using Selenium and Codeception

Whenever I run tests on Chrome using Codeception in Selenium server, I encounter random errors like the ones below: WebDriver\Exception\UnknownError: The current platform is not supported: LINUX WebDriver\Exception\UnknownError: Unabl ...

What approach can be taken to establish a dependency between an AngularJS controller and a value that is retrieved through ajax and loaded onto the root

I have an app that loads like this: app.js file: angular.module('App', []).run(['$rootScope', '$q', 'SessionManager', 'EndpointService', function ($rootScope, $q, SessionManager, EndpointService) { $r ...

What steps are required to insert additional tags into select2?

I've successfully retrieved the tags from my API, but I'm facing an issue with adding new tags. Here's the code snippet I've been using: $(function(){ var user_email = localStorage.getItem('email'); var api = ...

"Typescript: Unraveling the Depths of Nested

Having trouble looping through nested arrays in a function that returns a statement. selectInputFilter(enteredText, filter) { if (this.searchType === 3) { return (enteredText['actors'][0]['surname'].toLocaleLowerCase().ind ...