Home Angularjs Filter Table contents based on a property

# Angularjs Filter Table contents based on a property

user4388
1#
user4388 Published in March 18, 2018, 2:12 am
 I am getting into some angular development and I am building a very simple example, but somehow I am stuck... (Yes, yes I know angular 5 is out and I should't be doing it with angularjs, but I am just interested to compare the different approaches) So my application has a simple Car object with an id, name and category. The categories are exactly 3 and based on them I am showing 3 tabs and based on the currently selected tab, I add a car to this particular category. Here is a screenshot: So while the adding and removal work fine, the displaying/filtering of cars based on the category doesn't and I am not sure what is the right approach here. My goal is that when I click on a 'tab', then I filter only the cars from that category. This is part of my simple controller: function CarController($scope, id, CarService) {$scope.allCars = []; $scope.name = '';$scope.currentCategory = 'Sport'; $scope.categories = ['Sport', 'Luxury', 'Normal'];$scope.addCar = addCar; $scope.deleteCar = deleteCar;$scope.setCurrentCategoryItem = function (item) { $scope.currentCategory = item; }; function addCar() { CarService.addCar($scope.name, $scope.currentCategory);$scope.name = ''; } Here I have a simple function that is responsible for persisting the data: function addCar(name, category, callback) { callback = callback || angular.noop; var Car = ResourceService.getResource(url, id); var newCar = new Car(); newCar.name = name; newCar.category = category; newCar.\$save(callback); } And here is my html template:

Cars

No duplicates allowed!
{{car.name}}
 You need to login account before you can post.
Processed in 0.31095 second(s) , Gzip On .