angularjs - iam trying to send data from angular services to nodejs backend Nothing happens -


i have enclosed service function here. iam trying send simple data node backend nothing happens. @ api endpoint things works saving data in shape(in postman). iam sure iam wrong somewhere here in angular no errors triggering. no http request raised.

app.service('userservices', function($rootscope, $http) {   this.addtoinvitelist = function(email, cb) {     var url = $rootscope.api_server_url + "/users/addtoinvitelist";     $http({       method: 'post',       url: url,       headers: {         'content-type': 'application/x-www-form-urlencoded'       } // set headers angular passing info form data (not request payload)     }).success(function(data) {       console.log("email posted sucessfully" + data);       cb(data);     })   } }) 

and controller code here,

app.controller('invitecontroller', function($scope, $rootscope, $routeparams, $location, userservices) {   $scope.addtoinvitelist = function(email) {     userservices.addtoinvitelist(email, function(dataresponse) {       console.log(dataresponse);     })   } }); 

and html view div below.

    <div class="tab-content">          <!--newsletter form-->                                 <div class="panel panel-minimalize">                                     <h2 class="signin-brand animated-hue"> <i class="fa fa-rocket"></i> medicoshere</h2>                                     <div class="panel-body bg-inverse ui-corner-all">                                         <form action="#">                                             <div class="form-group">                                                 <label for="subcribenewsletter" class="control-label">invite form<br> <small>we happy invite medicoshere, please enter email id in below form.</small></label>                                                 <div class="input-group input-group-in input-group-sm">                                                     <div class="input-group-addon"><i class="fa fa-envelope text-belpet"></i></div>                                                     <input class="form-control" id="subcribenewsletter" placeholder="johndoe@mail.com" ng-model="email" required>                                                     <div class="input-group-btn">                                                         <button type="submit" class="btn btn-default text-belpet" ng-click="addtoinvitelist(email)"><strong>ok</strong></button>                                                     </div>                                                 </div>                                             </div><!-- /.form-group -->                                         </form><!-- /form -->                                     </div><!-- /.panel-body -->                                 </div><!-- /.panel -->                                 <!--/end newsletter form-->                             </div><!-- /.cols -->  </main> 

will nice have bit more of information regarding problem see potential issues.

first of hope app variable (app.service) instance of angular's main module.

also, believe must return function in object @ begging or end of service declaration. way it'll work expected when calling controller.

so believe should this:

var app = angular.module('myapp'); app.service('userservices', function($rootscope, $http) {  this.addtoinvitelist = function(email, cb) {         var url = $rootscope.api_server_url + "/users/addtoinvitelist";         $http({             method: 'post',             url: url,            headers: { 'content-type': 'application/x-www-form-urlencoded '         }      // set headers angular passing info form data (not request payload) })     .success(function(data) {            console.log("email posted sucessfully" + data);            cb(data);    })  }    return {          addtoinvitelist:addtoinvitelist    } }) 

sorry bad indentation :) writing smartphone.

hope helps!

edit

also, sure added file index.html? :d

another thing check

you might want check in routing ok. perhaps you're not associating view right controller. or not including service file 1 of reasons you're not getting errors.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -