0

I have tried everything but I can't get it.

What i need is to access data filtered in ng-repeat from controller.

Data in ng-repeat is taken from a $http call.

$http.get('http://localhost:/test/test.php').success(function(data) {

 $scope.registros = data;

 });

and this is the view

<div ng-repeat="registro in (filteredregistros = (registros| filter:userSearch | filter:datefilter | filter:greaterThan('ID', greatersearch) |  orderBy:'-ID'))">


             {{registro.ID}}{{registro.date}}

             <div class="rowboxdata ng-animate">

                                        <div class=""><div class="name-business">{{registro.Name}}</div></div>
                                        <div class=""><div class="name-business">{{registro.Phone}}</div></div>
                                        <div class=""><div class="name-business">{{registro.Email}}</div></div>
                                        <div class=""><div class="name-business">{{registro.Name}}</div></div>
                                        <div class=""><div class="name-business">{{registro.City}}</div></div>
                                        <div class=""><div class="name-business">{{registro.Service}}</div></div>
             </div>

</div>

I have tried access data filtered from my controller with $scope.filteredregistros as i look in other post, but it didn't work to me.

What I'm trying to do, is to get data filtered and then, send it through ajax to php.

Would be nice some help thanks.

EDITED

Finally, I have found what I needed with this example;

In the View:

<input type="button" ng-click="results(filteredregistros)" />

In the Controller:

$scope.results = function (filteredregistros) {
          console.log(filteredregistros);
          // your ajax code
};

And if you want to get it only in the view, then do it as Per Hornshøj-Schierbeck says:

filteredregistros: {{filteredregistros | json}}

Thanks for the help Per Hornshøj-Schierbeck

4
  • Can you provide me sample json? Commented Jan 13, 2016 at 10:10
  • Show the example where you try to read your filteredregistros. Remember that data won't be accessible untill your http request completes and the filter code run... Commented Jan 13, 2016 at 10:12
  • @PerHornshøj-Schierbeck well all i tried was var test1 = $scope.filteredregistros; console.log(test1) Commented Jan 13, 2016 at 11:20
  • @PareshGami the sample json result is here, in a comment in the reply from per hornshoj Commented Jan 13, 2016 at 12:12

1 Answer 1

1

Try adding

filteredregistros: {{filteredregistros | json}}

in your HTML somewhere. It should be clear if it contains data or not. Piping it through json will display the data in json format, which is nice for debugging the value inside.

The reason why you might not see if, when you do console.log is, that depending on when you console.log it, your http request might or might not have run and the data might not be filtered yet.

Sign up to request clarification or add additional context in comments.

4 Comments

What are your registros values then? You can debug them either in the HTML or just console.log the data in your success method on the $http.get call
I forgot to change in my php mysql_fetch_array to mysql_fetch_object thats why it returned numbers and properties instead of properties
So did it solve your problem or what is the problem now?
Finally !! it was something stupid but.. this worked. In the click button ng-click="select(filteredregistros)" and then in the controller $scope.select = function (filteredregistros) { console.log(filteredregistros); }; and this returned me the objects i filtered and only the results. Thanks for your help @Per Hornshøj-Schierbeck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.