Search code examples
angularjs-scopeangularjs-filter

Angular 1 filter array not updating


I really wish I was doing something wrong here. Please see my js bin. http://jsbin.com/benewetewe/1/edit?html,js,output

Some user-story:

  1. When I check items and click "archive", it filters all "bought:true" away.
  2. When I click the "show history", it shows back all items whether its "bought:true" or not.
  3. But I noticed a problem, when I add new item in the list and click "archive", the new item is hid even if it's not yet "bought:true".
  4. But If I try to select & de-select the new item, it will now be part of the hid items when "archive" is clicked.

Anything I missed?

Thanks!


Solution

  • You have a small typo in your code, which caused the problem :

    $scope.toBuyAddItem = function (toBuyItem) {
        toBuyItem.bough = false;  /* <-- typo : change .bough to .bought */
        $scope.toBuyList.push(toBuyItem);
        $scope.toBuyItem = {};
    };
    

    Add a letter 't' to fix all your problems ;)