javascript - Angular JS : Filter using textbox and Checkbox -
i'm new angularjs , want filter data using textbox checkbox.
here data:
$scope.array = [ {name: 'tobias', lname: 'tlname', company: 'x'}, {name: 'jeff', lname: 'jlname', company: 'x'}, {name: 'brian', lname: 'blname', company: 'x'}, {name: 'igor', lname: 'ilname', company: 'y'}, {name: 'james', lname: 'jlname', company: 'z'}, {name: 'brad', lname: 'blname', company: 'y'} ];
all want if going choose x checkbox show rows related tobias jeff brian , if i'm going uncheck checkbox , type br, brian , brad show if i'm going check x checkbox bryan should show.
thanks in advance.
you use filters accomplish this.
see fiddle: http://jsfiddle.net/w4xqv/16/
markup:
<div ng-app="app" ng-controller="mainctrl"> <div>search name: <input type="text" ng-model="filters.search"></div> <div>show company x: <input type="checkbox" ng-model="filters.x" ng-change="actions.updatecompany()"/> </div> <div ng-repeat="arr in array | filter:filters.search | filter:{company: filters.company}"> <span ng-bind="arr.name"></span> </div> </div>
javascript:
var app = angular.module('app', []); app.controller('mainctrl', function($scope) { $scope.filters = { x: false, company: '', search: '' }; $scope.actions = { updatecompany: function () { if($scope.filters.x) { $scope.filters.company = 'x'; } else { $scope.filters.company = ''; } } }; $scope.array = [ {name: 'tobias', lname: 'tlname', company: 'x'}, {name: 'jeff', lname: 'jlname', company: 'x'}, {name: 'brian', lname: 'blname', company: 'x'}, {name: 'igor', lname: 'ilname', company: 'y'}, {name: 'james', lname: 'jlname', company: 'z'}, {name: 'brad', lname: 'blname', company: 'y'} ]; });
hope helps.
Comments
Post a Comment