I've been avoiding asking this here as there are loads of examples out there but I have no idea what's I'm doing wrong.
I'm trying to put a little angular app in place but I'm struggling to get it working pass the very basics.
I want to get a little CRUD happening but using a reasonable clean structure that I could use as a template for other apps.
I've found millions of examples but only using controllers and I found millions of examples on how to implement and DI services. I'm now trying to put them together but no joy.
Additionally, it looks like you're expecting $http.get() to return the data directly - it actually returns a promise with the response of the request as an argument. You need to use it like this (assuming your REST call returns the object you need):
Your RefDataService declaration looked more like factory than service (you should read about the difference for example [here])(AngularJS: Service vs provider vs factory). Module.service expects a constructor function which is on injection invoked with new operator so here I attach accountTypes method to this
In your controller you then use the service as Joe Clay described in his answer
I fixed $scope.accounts.push(this.account); to $scope.accounts.push($scope.account);. You would use this.account if you were using the controllerAs syntax.
Asked in February 2016Viewed 2,920 timesVoted 7Answered 2 times