hi bsr!
It is hart to see exactly what is going on without having a live,
running code (jsFiddle would be of great help here!) but just looking
at your example it seems like you are trying to access a service
directly in your template. This won't work since in a template you've
got only access to things defined in a scope.
I don't know if the above explanation makes sense to you so please
send a jsFiddle if you need more help.
Cheers,
Pawel
On Wed, Jul 25, 2012 at 9:56 PM, bsr <
bsr...@gmail.com> wrote:
> Hello,
>
> I am not sure this is the best way to do this, but I wrote a service to get
> search response from server.
>
> angular.module('xxx', []).service('Search', function($http) {
> this.find = function(q) {
> $http({method: 'GET', url:'/api/search', params:{ q: q}})
> .success(function (data) {
> return data;
> });
> };
> });
>
> I am calling this from view.
>
> <form class="form-search">
> <input type="text" class="search-query" placeholder="Search"
> ng-model="q">
> </form>
> <a class="btn" ng-click="result =Search.find(q)" href="">Search</a>
>
> Now,
> Search.find(q) does send http GET request, and I can see the response. But
> not sure how to assign the return value to a variable (say result) of scope
> ($scope. result).
>
> Is there a better way I should approach this. I did not use resource because
> I don't want to send a request, if user does not use Search functionality.
> and I may only do search (no save, update etc)
>
> thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/angular/-/Q8HrthZDtL0J.
> To post to this group, send email to
ang...@googlegroups.com.
> To unsubscribe from this group, send email to
>
angular+u...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/angular?hl=en.