Dynamically setting a filter variable in AngularJS through an infoWindow

My select box is successfully interacting with the Angular list. The 'citta' field in the select box filters the list when its value changes.

ng-model="queryLoc.citta"

First, I initialize the variable

$scope.queryLoc = { citta: ''};

Now, I want to set the queryLoc value by clicking a button inside a Google Maps infoWindow. When the button is clicked, I use this code to call the 'filtraLoc' function:

angular.element(document.getElementById('eventCont')).scope().filtraLoc(citta);

This is what the 'filtraLoc' function does:

$scope.filtraLoc = function(city){
    $scope.queryLoc = {citta: city};
};

In my JSON data, there is an attribute called 'citta' as shown below:

{   
    immagine:'/upload/cms/770_x/Lonato(2).jpg',
    linkScheda: '/cms-01.00/articolo.asp?IDcms=77193&s=269',
    nome: 'MERCATO CONTADINO A LONATO DEL GARDA',
    citta: 'Lonato del Garda',
    data: 'OGNI SABATO MATTINA DALLE ORE 8 ALLE 13',
    categoria: '', 
    latitudine: '8', 
    longitudine: '82', 
    show: 'false'
}

However, the filter is not working correctly and I am unable to find any errors in the browser console. Any help or tips would be greatly appreciated. Thank you.

Answer №1

Solution Found:

Simply utilize the $digest function and modify the code from this:

angular.element(document.getElementById('eventCont')).scope().filtraLoc(citta);

to this:

var temp = angular.element(document.getElementById('eventCont'));
temp.scope().queryLoc  = {citta: city};
temp.scope().$digest();

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

`You may encounter a error message indicating "ReferenceError: <package> not defined" even after successfully installing the package.`

After successfully running the command npm install chevrotain in a specific folder, I checked the version with npm -v chevrotain, leading me to get 8.1.2. In my package.json file, I have "chevrotain": "^10.1.2" listed under dependencies ...

What is the best way to minimize the number of requests sent in AngularJS?

Currently in my demo, each time a user types something into an input field, a request is sent to the server. However, I would like only one request to be fired. For example, if the user types "abc," it currently fires three requests. Is there a way for the ...

Guide on incorporating an Angular directive to substitute an element under specific conditions

My goal is to create a directive that replaces an anchor element with a div element under certain conditions. The content of the anchor element should remain unchanged and be included within the new element. The concept involves having an attribute on the ...

The initialization of the R Shiny HTML canvas does not occur until the page is resized

I am currently facing an issue while integrating an HTML page with a canvas into my shiny R application using includeHTML(). The packages I am using are shiny, shinydashboard, shinycssloaders, dplyr, and DT. Everything is working perfectly fine except for ...

Obtaining JSON data from a PHP script using AngularJS

I've been exploring an AngularJS tutorial on a popular website called w3schools. Check out the tutorial on w3schools After following the tutorial, I modified the script to work with one of my PHP scripts: <!DOCTYPE html> <html > <sty ...

Bind event listener exclusively for click event handlers

I have a scenario where I am using 'addEventListener' to handle the opening of a menu (genres-container) only after the transition on another menu (mobile-nav) has completed. The issue I am facing is that even after closing everything and trying ...

Executing Python and JavaScript with Selenium

I am encountering an issue while trying to run this code. The error message indicates that I may be missing a closing ) or using an illegal character. It seems like there might be confusion with inserting arguments where they are not needed. Could someon ...

Substitute any text string starting with a colon, such as the route path in Express

Below are some sample strings: const a = '/example/:someItemUuid/hello' const b = '/example/:someItemUuid/hello/:otherItemUuid' const params = { someItemUuid: '12345', otherItemUuid: '67890' } I am in search o ...

What is the best way to apply a filter to an array of objects nested within another object in JavaScript?

I encountered an issue with one of the API responses, The response I received is as follows: [ {type: "StateCountry", state: "AL", countries: [{type: "County", countyName: "US"}, {type: "County", countyNa ...

Maintain functionality of React components even when they are not actively displayed

I have a unique page React app with different components. The App.js file controls which component to display based on server information. One specific component, the Stopwatch, is only rendered on two of the pages. Here's a snippet of code from my Ap ...

What is the best method for incorporating a JavaScript redirect into an Android WebView?

My issue involves loading a page into a webview. Typically, when I use the code webview.loadUrl(url); it functions as expected. The url contains a javascript code that redirects the page. Here is the javascript code: <script type="text/javascript"> ...

Utilizing Shopify API to seamlessly add items to cart without any redirection for a smoother shopping experience

Looking for a solution to submit an add to cart POST request without any redirection at all? I have tried changing return_to to "back" but that still reloads the page, which is not ideal. My goal is to smoothly add the item to the cart and notify the cli ...

Creating a list in Angular.js using the ng-repeat directive to iterate through data from

Recently, I started my journey with Angular.js and encountered my first small hurdle. This snippet is from my hello.js file: function Hello($scope, $http) { $http.get('URL'). success(function(data) { $scope.response = data });} The resp ...

none of the statements within the JavaScript function are being executed

Here is the code for a function called EVOLVE1: function EVOLVE1() { if(ATP >= evolveCost) { display('Your cell now has the ability to divide.'); display('Each new cell provides more ATP per respiration.'); ATP = ATP ...

Issue with Jquery plugin malfunctioning on dynamically loaded elements via Ajax requests

Description: I'm currently working on a project where I need to load elements with expiration dates pulled from my database. To achieve this, I am using a Jquery plugin that relies on the HTML5 Data Type Attribute for setting the "end date". Everythin ...

Learn the process of adding a key and value into an array using Angular

I need to filter data based on the number of rows and columns provided by the user. After reading an excel file, I extract the data in the controller: https://i.sstatic.net/vPpxL.png These are the column headers retrieved after the user entered 5 as the ...

Updating the video tag's source attribute using JSON information

I am in the process of creating a unique video player using HTML and Javascript that will sequentially play a set of videos until all 6 have been displayed. The URLs for these videos are stored within an array that is mapped in a .json file named clips.jso ...

React.Js custom form validation issue in Next.Js - troubleshooting required

My attempt at validating a form is causing some issues. After refreshing the page and clicking on the submit button, only the last input's error is generated instead of errors for every input according to the validation rules. Here is a screenshot o ...

Inserting a multidimensional array into a JSON structure

Currently, I am working on populating my mongodb database with data that needs to be in a specific format. var location1 = [2,3]; var location2 = []; location2.push(location1); location2.push(location1); var location3 = []; location3.push(location2); cons ...

Conceal Element in React if it is the Final Item

Is there a way to hide the TimelineConnector if it is on the last item? I am looking for some guidance on how to achieve this. Please take a look at my codesandbox below: CLICK HERE {timelines.lastIndexOf(index) !== 1 ? <TimelineConnector /> : &quo ...