Angular $filter is filtering negative numbers even though the filter is a positive number










1














I have a simple filter for a array. each item in the array has a 'Rating' attribute that is a number. The values can be -3,-2,-1,1,2,3.



If I do



$scope.ratingFilter = -3; // negative numbers work fine



BUT if I do



$scope.ratingFilter = 3; // positive numbers are showing items that have a Rating of 3 AND -3. Why are negative number appearing in the filter???



$scope.updateMarkers = function()

var filters = ;
if($scope.ratingFilter != 'all')
filters.Rating = $scope.ratingFilter;


var arr = ;
angular.forEach($scope.allMarkers, function(value, key)
arr.push(value);
);

$scope.markers = $filter('filter')(arr, filters);










share|improve this question























  • Isn't it a string filter?
    – Frank Modica
    Nov 12 '18 at 23:27










  • @FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
    – Jamie Barker
    Nov 12 '18 at 23:30










  • I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
    – Frank Modica
    Nov 12 '18 at 23:32











  • @FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
    – Jamie Barker
    Nov 12 '18 at 23:34










  • @FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
    – Jamie Barker
    Nov 12 '18 at 23:37















1














I have a simple filter for a array. each item in the array has a 'Rating' attribute that is a number. The values can be -3,-2,-1,1,2,3.



If I do



$scope.ratingFilter = -3; // negative numbers work fine



BUT if I do



$scope.ratingFilter = 3; // positive numbers are showing items that have a Rating of 3 AND -3. Why are negative number appearing in the filter???



$scope.updateMarkers = function()

var filters = ;
if($scope.ratingFilter != 'all')
filters.Rating = $scope.ratingFilter;


var arr = ;
angular.forEach($scope.allMarkers, function(value, key)
arr.push(value);
);

$scope.markers = $filter('filter')(arr, filters);










share|improve this question























  • Isn't it a string filter?
    – Frank Modica
    Nov 12 '18 at 23:27










  • @FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
    – Jamie Barker
    Nov 12 '18 at 23:30










  • I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
    – Frank Modica
    Nov 12 '18 at 23:32











  • @FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
    – Jamie Barker
    Nov 12 '18 at 23:34










  • @FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
    – Jamie Barker
    Nov 12 '18 at 23:37













1












1








1







I have a simple filter for a array. each item in the array has a 'Rating' attribute that is a number. The values can be -3,-2,-1,1,2,3.



If I do



$scope.ratingFilter = -3; // negative numbers work fine



BUT if I do



$scope.ratingFilter = 3; // positive numbers are showing items that have a Rating of 3 AND -3. Why are negative number appearing in the filter???



$scope.updateMarkers = function()

var filters = ;
if($scope.ratingFilter != 'all')
filters.Rating = $scope.ratingFilter;


var arr = ;
angular.forEach($scope.allMarkers, function(value, key)
arr.push(value);
);

$scope.markers = $filter('filter')(arr, filters);










share|improve this question















I have a simple filter for a array. each item in the array has a 'Rating' attribute that is a number. The values can be -3,-2,-1,1,2,3.



If I do



$scope.ratingFilter = -3; // negative numbers work fine



BUT if I do



$scope.ratingFilter = 3; // positive numbers are showing items that have a Rating of 3 AND -3. Why are negative number appearing in the filter???



$scope.updateMarkers = function()

var filters = ;
if($scope.ratingFilter != 'all')
filters.Rating = $scope.ratingFilter;


var arr = ;
angular.forEach($scope.allMarkers, function(value, key)
arr.push(value);
);

$scope.markers = $filter('filter')(arr, filters);







angularjs filter negative-number






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 23:12







Jamie Barker

















asked Nov 12 '18 at 23:11









Jamie BarkerJamie Barker

73110




73110











  • Isn't it a string filter?
    – Frank Modica
    Nov 12 '18 at 23:27










  • @FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
    – Jamie Barker
    Nov 12 '18 at 23:30










  • I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
    – Frank Modica
    Nov 12 '18 at 23:32











  • @FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
    – Jamie Barker
    Nov 12 '18 at 23:34










  • @FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
    – Jamie Barker
    Nov 12 '18 at 23:37
















  • Isn't it a string filter?
    – Frank Modica
    Nov 12 '18 at 23:27










  • @FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
    – Jamie Barker
    Nov 12 '18 at 23:30










  • I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
    – Frank Modica
    Nov 12 '18 at 23:32











  • @FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
    – Jamie Barker
    Nov 12 '18 at 23:34










  • @FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
    – Jamie Barker
    Nov 12 '18 at 23:37















Isn't it a string filter?
– Frank Modica
Nov 12 '18 at 23:27




Isn't it a string filter?
– Frank Modica
Nov 12 '18 at 23:27












@FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
– Jamie Barker
Nov 12 '18 at 23:30




@FrankModica Hmmm, I'm not sure what you mean. Rating attribute in the arr array is a number not a string. I'll check what $scope.ratingFilter is but I'm sure it's a number.
– Jamie Barker
Nov 12 '18 at 23:30












I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
– Frank Modica
Nov 12 '18 at 23:32





I mean the filter provided by AngularJS - it might be returning anything that contains 3. Try adding another number that has a 3 in it and see if it returns that too.
– Frank Modica
Nov 12 '18 at 23:32













@FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
– Jamie Barker
Nov 12 '18 at 23:34




@FrankModica console.log(angular.isString($scope.ratingFilter)); returns false so it is a number.
– Jamie Barker
Nov 12 '18 at 23:34












@FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
– Jamie Barker
Nov 12 '18 at 23:37




@FrankModica ok... i just did $scope.ratingFilter = 43; and that returned 0 results so it's not a partial match. Whats strange is that -1,-2,-3 all work and you would think that if it was any number with 3 that it would also return all the positive 3's. very strange.
– Jamie Barker
Nov 12 '18 at 23:37












3 Answers
3






active

oldest

votes


















0














Consider filtering the array yourself in the controller with plain JavaScript:



$scope.markers = arr.filter(x => x.Rating === ratingFilter);





share|improve this answer




















  • Thanks Frank, see my answer below. Solved the issue for me.
    – Jamie Barker
    Nov 13 '18 at 0:06










  • @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
    – Frank Modica
    Nov 13 '18 at 0:09






  • 1




    Yo Frank, It quite a massive app. 2+ years dev so far.
    – Jamie Barker
    Nov 13 '18 at 2:54










  • Gotcha, makes sense
    – Frank Modica
    Nov 13 '18 at 12:45


















0














Set the 'strict' value to truein the $filter.



$filter('filter')(arr, filters, true);



see https://docs.angularjs.org/api/ng/filter/filter






share|improve this answer




























    0














    $scope.dsset = $filter('filter')($scope.array, id: 1);






    share|improve this answer




















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271440%2fangular-filter-is-filtering-negative-numbers-even-though-the-filter-is-a-positi%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Consider filtering the array yourself in the controller with plain JavaScript:



      $scope.markers = arr.filter(x => x.Rating === ratingFilter);





      share|improve this answer




















      • Thanks Frank, see my answer below. Solved the issue for me.
        – Jamie Barker
        Nov 13 '18 at 0:06










      • @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
        – Frank Modica
        Nov 13 '18 at 0:09






      • 1




        Yo Frank, It quite a massive app. 2+ years dev so far.
        – Jamie Barker
        Nov 13 '18 at 2:54










      • Gotcha, makes sense
        – Frank Modica
        Nov 13 '18 at 12:45















      0














      Consider filtering the array yourself in the controller with plain JavaScript:



      $scope.markers = arr.filter(x => x.Rating === ratingFilter);





      share|improve this answer




















      • Thanks Frank, see my answer below. Solved the issue for me.
        – Jamie Barker
        Nov 13 '18 at 0:06










      • @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
        – Frank Modica
        Nov 13 '18 at 0:09






      • 1




        Yo Frank, It quite a massive app. 2+ years dev so far.
        – Jamie Barker
        Nov 13 '18 at 2:54










      • Gotcha, makes sense
        – Frank Modica
        Nov 13 '18 at 12:45













      0












      0








      0






      Consider filtering the array yourself in the controller with plain JavaScript:



      $scope.markers = arr.filter(x => x.Rating === ratingFilter);





      share|improve this answer












      Consider filtering the array yourself in the controller with plain JavaScript:



      $scope.markers = arr.filter(x => x.Rating === ratingFilter);






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 12 '18 at 23:58









      Frank ModicaFrank Modica

      6,1182727




      6,1182727











      • Thanks Frank, see my answer below. Solved the issue for me.
        – Jamie Barker
        Nov 13 '18 at 0:06










      • @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
        – Frank Modica
        Nov 13 '18 at 0:09






      • 1




        Yo Frank, It quite a massive app. 2+ years dev so far.
        – Jamie Barker
        Nov 13 '18 at 2:54










      • Gotcha, makes sense
        – Frank Modica
        Nov 13 '18 at 12:45
















      • Thanks Frank, see my answer below. Solved the issue for me.
        – Jamie Barker
        Nov 13 '18 at 0:06










      • @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
        – Frank Modica
        Nov 13 '18 at 0:09






      • 1




        Yo Frank, It quite a massive app. 2+ years dev so far.
        – Jamie Barker
        Nov 13 '18 at 2:54










      • Gotcha, makes sense
        – Frank Modica
        Nov 13 '18 at 12:45















      Thanks Frank, see my answer below. Solved the issue for me.
      – Jamie Barker
      Nov 13 '18 at 0:06




      Thanks Frank, see my answer below. Solved the issue for me.
      – Jamie Barker
      Nov 13 '18 at 0:06












      @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
      – Frank Modica
      Nov 13 '18 at 0:09




      @JamieBarker You're welcome. But I'm curious, why bring AngularJS in for this when it can be done with standard JS?
      – Frank Modica
      Nov 13 '18 at 0:09




      1




      1




      Yo Frank, It quite a massive app. 2+ years dev so far.
      – Jamie Barker
      Nov 13 '18 at 2:54




      Yo Frank, It quite a massive app. 2+ years dev so far.
      – Jamie Barker
      Nov 13 '18 at 2:54












      Gotcha, makes sense
      – Frank Modica
      Nov 13 '18 at 12:45




      Gotcha, makes sense
      – Frank Modica
      Nov 13 '18 at 12:45













      0














      Set the 'strict' value to truein the $filter.



      $filter('filter')(arr, filters, true);



      see https://docs.angularjs.org/api/ng/filter/filter






      share|improve this answer

























        0














        Set the 'strict' value to truein the $filter.



        $filter('filter')(arr, filters, true);



        see https://docs.angularjs.org/api/ng/filter/filter






        share|improve this answer























          0












          0








          0






          Set the 'strict' value to truein the $filter.



          $filter('filter')(arr, filters, true);



          see https://docs.angularjs.org/api/ng/filter/filter






          share|improve this answer












          Set the 'strict' value to truein the $filter.



          $filter('filter')(arr, filters, true);



          see https://docs.angularjs.org/api/ng/filter/filter







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 '18 at 23:58









          Jamie BarkerJamie Barker

          73110




          73110





















              0














              $scope.dsset = $filter('filter')($scope.array, id: 1);






              share|improve this answer

























                0














                $scope.dsset = $filter('filter')($scope.array, id: 1);






                share|improve this answer























                  0












                  0








                  0






                  $scope.dsset = $filter('filter')($scope.array, id: 1);






                  share|improve this answer












                  $scope.dsset = $filter('filter')($scope.array, id: 1);







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 6:35









                  alokalok

                  1




                  1



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53271440%2fangular-filter-is-filtering-negative-numbers-even-though-the-filter-is-a-positi%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                      Museum of Modern and Contemporary Art of Trento and Rovereto