Why is the AngularJS slider not showing its range value?

I'm currently working on implementing an AngularJS slider bar that I found through a Google search. I've been able to filter it based on my slider selection, but I'm struggling to display the minimum and maximum range values at the beginning and end of the slider bar (either on top or at the starting/ending points).

Here's an example:

https://i.sstatic.net/XAmkT.png

If I use something like:

<slider floor="0" ceiling="50" ng-model-low="lower_price_bound" ng-model-high="upper_price_bound"></slider>
, then the slider filters fine (though it doesn't show any range values on top of the slider bar).

However, if I try something like:

<slider floor="0" ceiling="50" ng-model-low="lower_price_bound" ng-model-high="upper_price_bound" ng-model="itemrange.maxvalue"></slider>
, then the filtering isn't working as expected when I move or adjust the slider. I was hoping it would also display the range values at the starting and ending points of the slider bar, but that's not happening. In this case, we're adding: ng-model="itemrange.maxvalue".

A demo link is available at Fiddle.

Here's the HTML code snippet:

<body ng-controller='PriceCtrl'>
    <slider floor="0" ceiling="50" ng-model-low="lower_price_bound" ng-model-high="upper_price_bound" ng-model="itemrange.maxvalue"></slider>
    lower_price_bound: <strong>{{lower_price_bound}}</strong>
    &nbsp;
    upper_price_bound: <strong>{{upper_price_bound}}</strong>
    <hr>
    <table border="1">
      <thead>
        <th>Name</th>
        <th>Min Price</th>
        <th>Max Price</th>
      </thead>
      <tbody>
        <tr ng-repeat='item in items | filter:priceRange'>
          <td>{{item.name}}</td>
          <td>{{item['min-acceptable-price']}}</td>
          <td>{{item['max-acceptable-price']}}</td>
        </tr>
      </tbody>
    </table>

  </body>

And here's the associated JavaScript code (app.js):

var app = angular.module('prices', ['uiSlider']);

app.controller('PriceCtrl', function ($scope){

    $scope.itemrange = {
    maxvalue: 50
  };

  $scope.items = [{name: "item 1", "min-acceptable-price": "10",
                  "max-acceptable-price": "50"},
                  {name: "item 2", "min-acceptable-price": "5",
                  "max-acceptable-price": "40"},
                  {name: "item 3", "min-acceptable-price": "15",
                  "max-acceptable-price": "30"}];

  $scope.lower_price_bound = 0;
  $scope.upper_price_bound = 50;

  $scope.priceRange = function(item) {
    return (parseInt(item['min-acceptable-price']) >= $scope.lower_price_bound && parseInt(item['max-acceptable-price']) <= $scope.upper_price_bound);
  };
});

I'd appreciate any insights on what I might be doing wrong. Thank you in advance.

Answer №1

When utilizing the "ng-model" parameter, you are replacing the previous two model parameters.

To select a range, simply use the "ng-model-low" and "ng-model-high" parameters.

If you wish to display the currently selected values above the sliders, you will need some customized CSS similar to this example.

For a simple solution, consider using a library like angularjs-slider.

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

Tips for executing a JavaScript function within a secure sandbox environment

My current setup involves an application server developed in JavaScript (node.js) where I receive JS function code as input from a web browser. Now, my goal is to execute this function on the server without any interference with other processes. I am look ...

Transforming an Ext.data.TreeStore data structure into a JSON format

How can I convert an Ext.data.TreeStore to a string for saving to Local Storage? I tried using Ext.encode() but it's giving me a circular structure error. Has anyone encountered this issue and found a workaround? ...

Difficulty Communicating Recapcha 2 with the PHP Script

I am currently testing the installation of reCaptcha 2 with server-side verification using a form with one input field. My process involves sending the reCaptcha response via Ajax to a PHP page for verification. While I am able to capture the information p ...

How can I trigger a PHP function from within an HTML onClick() event?

While I have come across a response on stackoverflow regarding form submission, my query pertains to a different implementation. I am in need of calling a function that registers a variable in $_SESSION[], and then redirects to another page (html/php). I ...

Is there a simple method to easily add a single or multiple columns for display within an ng-repeat loop?

My current view is impeccable, showcasing a list of items. The business team, always on top of things, is looking to insert a promotional program between two ng-repeated list elements. What is the best approach to achieve this? Any ideas? ...

Receiving Array Data from JSON and Listing Results

Once I retrieve the first row result from a JSON array, I want to display all the results using the jQuery each method. Here is the code snippet: $(document).ready(function () { $("#btnsearch").click(function() { valobj = $('#search_box' ...

Three.js Pin Placement for Clothing

I am in need of assistance! I am currently working on a simulation involving a cloth that is attached to four corners. I am attempting to reposition the pins at coordinates 0, 10, 88, 98 within a 10x10 array. My goal is to place each pin at a different pos ...

I'm having trouble with my TextGeometry not displaying on screen. Can someone help me figure

Here is the code I am using for Three.js: <html> <head> <title>My first Three.js app</title> <style> body { margin: 0; } canvas { width: 100%; height: 100% } </style> ...

Ensure that a string contains only one instance of a specific substring

I need a function that removes all instances of a specific substring from a string, except for the first one. For example: function keepFirst(str, substr) { ... } keepFirst("This $ is some text $.", "$"); The expected result should be: This $ is some tex ...

Access the array value in AngularJS based on a different property array

Here are my Arrays: var FirstArr=[ { "id":"123", "aboutUS":"Demo About Us" }, { "id":"234", "tutorial":"Demo Tutorial" } ...

The reducer and the store are experiencing a lack of synchronization

I'm having trouble figuring out what's going on with my json file that contains a list of products. I'm trying to render specific ones, but it's not working as expected. Here's the reducer code I'm using: export default(stat ...

"Expand" Button following X buttons

Check out this JSFiddle for the code: $(document).ready(function(){ $( ".keywordsdiv" ).each(function(){ $(this).children(".keywords").eq(3).after('<a href="" id="playtrailershowmorebuttons">....Show More</a>');//add a uniq ...

In a production environment, an ENOENT error in Next.js was triggered by fs.readdirSync

Utilizing the Next.js App Router, I attempted to retrieve all my markdown posts stored in files by scanning a directory using fs.readdirSync(). While everything worked flawlessly locally, upon deploying on Vercel, an unexpected issue arose. The code was e ...

Tips for identifying memory leaks in an Angular app?

My webapp, developed using AngularJS, is designed to poll an API with two endpoints every minute to check for updates. Despite my efforts to pinpoint a small memory leak in the app, I have been unsuccessful. However, I did manage to reduce overall memory ...

The directive is not responding to the click event because it is being stopped by event.stopPropagation called from an external

I am facing an issue with a directive and its child element. The child element (inside the directive template) has a click event, while the element outside the directive (section tag) also has a click event. In order to prevent the click event from bubblin ...

Retrieve the key value pairs exclusively when utilizing the find method on a JSON array in JavaScript

To extract a value from a JSON array, I am utilizing the find method in this manner: let actualElm = this.initialData.find(elm => { if (elm.identifiant == this.actualId) { return elm.country; } }); An issue with using find is that it returns t ...

jQuery performs a synchronous call and executes the code

The code snippet above demonstrates a situation where the API execute_wc is invoked, triggering a recursive function call to poll_results. The function only returns when the status is not equal to 1. However, due to the asynchronous nature of the poll_resu ...

Guide on incorporating the Chain Pattern alongside the Self Revealing Module Pattern within JavaScript

I have come across the following code snippet: filtersManager = (function ($) { var that = this; function initialize() { // some tasks return that; }; function execute() { // some tasks return that; ...

JavaScript creating popup windowsAlternatively: JavaScript-empowered

After spending hours searching, I still haven't found the answer I'm looking for. That's why I'm reaching out here with a question. How can I incorporate pop-up windows or click functions into an existing map like this one: ? I am aimi ...

Retrieving the source code via JQuery Ajax

I've been implementing JQuery Ajax on my website and encountered an issue. It's working perfectly fine on our test server, but when I transferred it to our live server, the Ajax response is just the source code of the website itself. Here's ...