Can't get value from form return undefined [AngularJs]

292 views Asked by At

I can't get value from input field in html.

This is my html:

<div class="form-group">
  <label class="control-label col-sm-2" for="subject">Subject:</label>
  <div class="col-sm-10">
    <input class="form-control" id="idsubject" ng-model="subject" placeholder="Enter Subject">
  </div>
</div>
<div class="form-group">
  <label class="control-label col-sm-2" for="body">Body:</label>
  <div class="col-sm-10">
    <input class="form-control" id="idbody" ng-model="body" placeholder="Enter Body">
  </div>
</div>

Then this is my controller insert:

// insert data
$scope.InsertData = function() {
  var insert = {
    subject: $scope.subject,
    body: $scope.body
  }
  var promiseGet = GetAllEntryService.InsertData(insert);
  GetAllEntry();
  ClearModels();
  promiseGet.then(function(pl) {
      $scope.InsertData = pl.data
    },
    function(errorPl) {
      console.log('Some Error in Getting Records.', errorPl);
    });
}

But this return value post like http://localhost:51458/ServiceRequest.svc/InsertData?subject=undefined&body=undefined

I don't know why from input field not get the value.

This is my service insert:

this.InsertData = function (ticket, request, category, subCategory, subject, body, assignto, status, fileName, fileContent, fileBinary, isActive, createdBy, aCNo) {
    return $http.post("http://localhost:51458/ServiceRequest.svc/InsertData?"&subject=" + subject + "&body=" + body);
};

this the picture output from inspect element developer network

Please help me what I'm missing in my code

enter image description here

1

There are 1 answers

1
Yaser On BEST ANSWER

I can see a couple of problems, first you are setting InsertData as a function and later you set it to data.

Then you have your service which takes separate params but you've pass an object to it:

this.InsertData = function (ticket, request, category, subCategory, subject, body, ...)

And your usage:

var insert = {
  subject: $scope.subject,
  body: $scope.body
}
var promiseGet = GetAllEntryService.InsertData(insert);

While you should've used it like this:

var promiseGet = GetAllEntryService.InsertData(/*ticket goes here*/, ... , $scope.subject, $scope.body, ...);