1

I am following the tutorial on nettuts Building a Web App From Scratch in AngularJS but using my own json call from google spreadsheet. Except the search filter doesn't seem to be working.

EDIT: Based on feedback, here is simplified example

    app.controller("mainController", function($scope, $http){
    $scope.results = [];
    $scope.filterText = null;
    $scope.init = function() {

    var sheet = "od6"; //upcoming classes
    var key = "0AhVWrVLsk5a5dDJyaW1LMXFEVk1UY0FPVlBVcHd1bGc";
    var url = "http://spreadsheets.google.com/feeds/list/" + key + "/" + sheet + "/public/values?alt=json-in-script";



    $http.jsonp(url + '&callback=JSON_CALLBACK').success(function(data) {

        angular.forEach(data, function(value, index){

        angular.forEach(value.entry, function(classes, index){

        $scope.results.push(classes);

                });

            });

        }).error(function(error) {

        });

    };

});

After that it seems to be fairly easy to set up, just like:

    <input type="text" ng-model="filterText" placeholder="Enter text here">
<ul>
    <li ng-repeat="classes in results | filter:filterText>
                    <h3>{{classes.gsx$title.$t}}</h3>
                <p>{{classes.gsx$description1.$t}}</p>
<ul>
                <li><strong>Start:</strong> {{classes.gsx$start.$t}} </li>
                <li><strong>End:</strong> {{classes.gsx$finish.$t}} </li>
                <li><strong>Price:</strong> {{classes.gsx$price.$t}} </li>
                <li><strong>Seats:</strong> {{classes.gsx$spots.$t}} </li>
                <li><strong><a href = "{{classes.gsx$url.$t}}">Sign up now</a></strong></li>
            </ul>
</li>

</li>
</ul>

but when i run filterText search, it doesn't give any results. the page comes up empty. here is full code example.

http://plnkr.co/edit/ZnVqyeQ9OWqwzjIEplOU?p=preview

here is json response:

json response

Huge thanks!

Yulia
  • 141
  • 2
  • 15

1 Answers1

1

Since you try to filter the text wrapped in object, you can try this approach:

This will show records with title containing whatever typed in the filterText search bar.

<li ng-repeat="classes in results | filter:{gsx$title.$t: filterText} | isCategory:categoryFilter">
zs2020
  • 53,766
  • 29
  • 154
  • 219
  • thanks! so if I want to filter through both title and description, should I set up two filters? – Yulia Jul 17 '13 at 14:23
  • @Yulia: two filters will be AND logic, you actually need OR logic, which means either title OR description should contain the keyword. In that case, you need to use a function. Please take a look at http://docs.angularjs.org/tutorial/step_09 – zs2020 Jul 17 '13 at 18:09