You have to inject your service in the controller. MyAccountController is
the one that needs to take a UsersFactory argument.
On Jul 7, 2014 5:37 AM, "Jayanta Pramanik" <[email protected]>
wrote:

> Hi,
> We are creating secured web application which is using Angular-JS in web
> portal. Call to Java REST service is being made from pages. But we can not
> make the REST call successfully. Here are code snippets for the Java side
> REST service -
>
> java code::
>
> @Path("/users")
> public class UserRestService {
> @POST
> @Consumes(MediaType.APPLICATION_JSON)
> @Produces(MediaType.APPLICATION_JSON)
> public User create(User user) {
> User user = new User();
> return user ;
> }
> }
>
> angular js code ::
> service.js
> -----------------------
> var consumerREST = angular.module('consumerRESTService', ['ngResource']);
>
> consumerREST.factory('UsersFactory', function ($resource) {
> var services = {
> doCreateUser : $resource('http://localhost:8080/demoApp/service/users',
> {}, {
> query: { method: 'GET', isArray: true },
> create: { method: 'POST' }
> })
> };
> return services;
> });
>
> controller.js
> ----------------------
> function MyAccountController($scope, $http){
> $scope.insertData = function (UsersFactory) {
> $scope.user = {id:1, firstname: 'AA', lastName: 'CC'};
> UsersFactory.doCreateUser($scope.user);
> }
>
> Error :: Following error is found in Javascript console of the browser -
>
> Cannot read property 'doCreateUser' of undefined
> at Object.MyAccountController.$scope.removeFetchedData1 (
> http://localhost:63342/angular-seed-master/app/js/controllers.js:358:21)
> at Object.MyAccountController.$scope.findAccountInfo (
> http://localhost:63342/angular-seed-master/app/js/controllers.js:334:16)
> .....
> ......
> Please help...
>
> Thanks in advance.
> Regards
> Jayanta Pramanik
>
>  --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to