Save filtered data

187 views
Skip to first unread message

Matt Nodurfth

unread,
May 21, 2013, 5:01:56 AM5/21/13
to ang...@googlegroups.com
New to AngularJS and loving it!  

I'm using ngRepeat to filter through JSON.  Is there a way to save the filtered items to another JSON?  I want to use the filtered results later on in my script.  

Cheers,
Matt

Raymond Z.

unread,
May 21, 2013, 12:50:02 PM5/21/13
to ang...@googlegroups.com
You can achieve this with the $filter service. Note that you need to use angular.toJson() on the filtered data because Angular adds $$hashKey key-value pairs to each JSON object.

Syntax:

    $filter('filter')(array, expression)


The code you want is on line 11, with $scope.save().

Message has been deleted

Matt Nodurfth

unread,
May 27, 2013, 2:07:40 AM5/27/13
to ang...@googlegroups.com
Thanks Raymond! Is there a way to do this without having a save button, ie, dynamically?

I'm working with leaflet.js and angular.  I'm filtering the imported json with angular and then want to have the map's markers built from that filtered json.  

Alfred Nutile

unread,
Mar 20, 2014, 3:39:43 PM3/20/14
to ang...@googlegroups.com
You ever figure this one out?

Matt Nodurfth

unread,
Mar 21, 2014, 12:14:13 AM3/21/14
to ang...@googlegroups.com
You could just set a watch on the input.  So that every time a character has been typed, it'll run the save().
This what you mean?


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/a1cBVLxJYFk/unsubscribe.

To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Tony pee

unread,
Mar 21, 2014, 12:25:06 AM3/21/14
to ang...@googlegroups.com
You can do this:

<li  ng-repeat="item in filtered = (myData | filter )">

this will set the result of the filtered MyData to a variable of filtered on the $scope. this is useful if you want to know when a filtered resultset is length=0 too - to show a 'no results' message for instance. 


i just made this to test myself acutally... yes, you need the brackets ;)




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Tony Polinelli

Tony pee

unread,
Mar 21, 2014, 12:27:19 AM3/21/14
to ang...@googlegroups.com
.. you can then watch the filtered value to save it back to json if you want
--
Tony Polinelli

Reply all
Reply to author
Forward
0 new messages