I am trying to search data with fix button value like when I click on veg button I want to only veg category data. right now my code is like. actually I am new learner for Angular js code.

First my button code:<butto id="veg" ng-click="myFilter = {type: 1}" title="veg">

My data display code:<div class="side-body padding-top fade in  tab-pane"  id="<?php echo $tt3->id; ?>">
                 <div class="row">
                 <div  ng-if='r.pro_category == <?php echo $tt3->id; ?>' ng-repeat = "r in groups | filter : searchGroups | filter:myFilter">
                    <div>
                        <div class="thumbnail">
                          <div><img src="../@{{r.image }}" alt="" /></div>
                          <div class="caption" style="padding-top:0px;">
                            <div>@{{r.pro_name }}</div>

                               <div>@{{r.price}}</div>

                    </div>
                    </div>
                    </div>

</div>
My script code: <script>
var GroupsApp = angular.module('GroupsApp',[]);
GroupsApp.controller('GroupsController', function ($scope, GroupsService) 
{

    getGroups();
    function getGroups() {
        GroupsService.getGroups()
            .success(function (grps) {
                $scope.groups = grps;

                 return (val.type != 2);

                console.log($scope.groups);
            })
            .error(function (error) {
                $scope.status = 'Unable to load Product data: ' + error.message;
                console.log($scope.status);
            });
    }
});

var url = window.location.pathname;
var productid = url.substring(url.lastIndexOf('/') + 1);
GroupsApp.factory('GroupsService', ['$http', function ($http) {


    var GroupsService = {};
    GroupsService.getGroups = function () {
        return $http.get('../showproduct/'+productid);
    };
    return GroupsService;
}]);

var url = window.location.pathname;
var productid = url.substring(url.lastIndexOf('/') + 1);
GroupsApp.factory('GroupsService', ['$http', function ($http) {


    var GroupsService = {};
    GroupsService.getGroups = function () {
        return $http.get('../showproduct/'+productid);
    };
    return GroupsService;
}]);
</script>

please help how to search data with button click.

share|improve this question
1  
Please only include relevant html, remove unnecessary classes for better readability – devqon Mar 24 at 8:22
    
@devqon I try to my code sort as possible i can. – solanki Mar 24 at 8:32
up vote 0 down vote accepted

Here is the example

<div ng-app ng-controller="Test">
  <button ng-click="myFilter = {type: 1}">veg</button> | 
  <button ng-click="myFilter = {type: 2}">non veg</button> |
  <button ng-click="myFilter = null">None</button>
  <ul >
    <li ng-repeat="person in persons | filter:myFilter">{{person.name}}</li>
  </ul>
</div>


function Test($scope) {
  $scope.persons = [{type: 1, name: 'cheese'}, {type:2, name: 'chicken'}, {type:1, name: 'carrot'}, {type:2, name: 'beaf'}];
    $scope.myFunction = function(val) {

    return (val.type != 2);
    };
}
share|improve this answer
    
..thanks for replay. can you put in my code.please – solanki Mar 24 at 8:49
    
i put your code and change my question but still its not working – solanki Mar 24 at 9:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.