How does Back button retain previous search?
[Couldn't find a way to contact you directly; hope it's OK that I ask this here. If I had this question, other readers might too.]
Thanks for your book; this was a really helpful introduction to AngularJS with RoR. When I was all done, there was just one thing that puzzled me. The 'Back' button is defined as:
<button ng-click="back()" class="btn btn-default">
and clicking that calls the back() function in RecipeController which looks like this:
$scope.back = -> $location.path("/")
The behavior you see in the browser (and that the specs validate is happening) is that when you click 'Back' you not only return to the root path, but the keywords you used in the previous search are still there. To achieve this I would have expected something like:
$scope.back = -> $location.path("/").search('keywords', keywords)
as it's done in RecipesController. Is there some magic about $location.path(...) that preserves whatever URL parameters there were before, or is there something else that accomplishes it? What would you do if you wanted a link/button that took you to the root path and cleared any previous keywords?
Yeah, this is a weird thing about $location. when you say $location.path(..) it means "change only the path of the current location" as opposed to the more intuitive "change everything about the current location to be this path" (which I think is what JavaScript's window.location actually does, making this more confusing).
So, to clear it, you are right, I think you'd have to do $location.path("/").search('keywords',null).
So, I guess I don't do that out of laziness :)