missing function identifier

268 views
Skip to first unread message

Brad Rice

unread,
Feb 4, 2013, 11:45:03 AM2/4/13
to ang...@googlegroups.com
I'm trying to create a http service so my model is available to both controllers in my app. However, I'm having an issue with creating the service.

In console.log I get "Uncaught SyntaxError: Unexpected identifier "

In plunkr it says "missing function identifier"


Can someone help a newbie understand what is wrong with the way I have written it?

Clint Checketts

unread,
Feb 4, 2013, 11:50:08 AM2/4/13
to ang...@googlegroups.com
Shouldn't you be returning an object {}, not a function? Try deleting the function keyword.



return function() {
    get : function(url, success, fail) {
      $http.get(url).success(function(response) {
        var data = response.data;
        if(!data) {
          onEmpty();
          return;
        }
        success();
      }).error(onEmpty);
    }
  };
}]);


--
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?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brad Rice

unread,
Feb 4, 2013, 11:55:47 AM2/4/13
to ang...@googlegroups.com
when I do that, I get an error No module: myHttp because I'm calling
it in my controller.
--
Brad Rice
brad...@gmail.com
~
"A man should look for what is, and not for what he thinks should be."
- Albert Einstein

Peter Bacon Darwin

unread,
Feb 4, 2013, 12:21:31 PM2/4/13
to ang...@googlegroups.com
Then don't call it in your controller!!  Instead call the get function

Clint Checketts

unread,
Feb 4, 2013, 12:29:32 PM2/4/13
to ang...@googlegroups.com
Brad,

I fiddled around with you plunkr a bit, it was missing the otehr controllers and the template files, also you didn't need to inject in $myHttp in the config method since services aren't available by then.

You also hadn't injected myHttp in your controller itself so you couldn't reference it.

last of all, in the index.html the ng-app attribute need to reference your app (myApp, not angularjs-starter)

Here I've made those changes:

-Clint

Brad Rice

unread,
Feb 4, 2013, 12:31:29 PM2/4/13
to ang...@googlegroups.com
That's what I am calling: $myHttp.get

Maybe I need to rethink this. I want the json object to be availalbe
to both controllers, so I was trying to write it as a service to the
app. I guess I'm not doing this right.
Reply all
Reply to author
Forward
0 new messages