I have a form, where in i submit a text using ng-click, now it calls a rest service and insert into the DB - working fine. at the same time, in same function, it calls another rest service but nothing is happening , i want to know how can I pass parameter to service???
Controller.js
app.controller('MyCtrl1', ['$scope', 'PostFactory', '$location', function ($scope, PostFactory, $location) {
/* callback for ng-click 'createUser': */
$scope.createPost = function () {
alert("in createPost" + $scope.UserPost.postText);
alert("in createPost" + $scope.UserPost);
PostFactory.postmain.create($scope.UserPost)
$scope.allposts.push($scope.UserPost);
$scope.UserPost = "";
$scope.allresultsfinal = PostFactory.allresults.query({tag: $scope.UserPost.postText})
$location.path('/view1');
}
$scope.allposts = PostFactory.postmain.query();
/*UserFactory.get({}, function (userFactory) {
$scope.firstname = userFactory.firstName;
})*/
}]);
Services.js
'use strict';
/* Services */
var services = angular.module('ngdemo.services', ['ngResource']);
//alert("In services");
services.factory('PostFactory', ['$resource', function ($resource) {
return {
postmain: $resource('/ngdemo/web/posts', {}, {
query: {method: 'GET', isArray: true },
create: {method: 'POST'}
}),
allresults: $resource('/ngdemo/web/posts/result/:tag', {id: '@id'}, {
query: {method: 'GET', params: {id: '@id'}, isArray: true },
create: {method: 'POST'}
})};
}]);
in allresults, id is not coming or I dont know if controll is reaching here or not. post submission in "postmain" and query is working fine. please let me know how to do it?
I need to send "tag" which is "#scope.UserPost.postText" as param in controller
$scope.allresultsfinal = PostFactory.allresults.query({tag: $scope.UserPost.postText})
to service.js "allresults" and get the data back from rest service.