خرید بک لینک

Vote count: 0

I have recently added two new fields to a form on a project I am working on and when I post/put a 'project', every field is uploaded except for the new ones, however, when I use Postman to post/put, those fields are sent and saved like all the others. When I console.log what is getting posted/put to the API, all the form data is there but only those two fields of 'price' and 'link' don't save to the api. I also have the form tied dynamically to what is being displayed and the when I make a PUT request, everything updates except the two fields that just retu to their original value. I'm trying for the life of me to figure out why this would be the case, double checking for any discrepancies with the new fields but I just can't seem to find the reason why it isn't saving.

Here is my controller:

"use strict";

(function() {
angular
  .module("softCity")
  .controller("showController", [
    '$scope',
    '$http',
    '$stateParams',
    'auth',
    ShowControllerFunction
  ]);

function ShowControllerFunction($scope, $http, $stateParams, auth) {

  var id = $stateParams.id;
  $scope.url = 'https://soft-city.herokuapp.com/api/projects/' + id;

  var vm = this;
  vm.mydata = {};

  var getProject = function() {
    $http.get($scope.url)
    .then(function(res) {
      vm.mydata = res.data;
    })
  };

  getProject();

  $scope.auth = auth;

  $scope.updateProject = function() {
    console.log(vm.mydata)
    $http({
        method: 'PUT',
        url: $scope.url,
        data: $.param(vm.mydata),
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      })
      .success(function(data) {
        console.log(data);
        getProject();
      })
  };

  $scope.removeField = function(){
    vm.mydata.img.pop();
  }

  $scope.addField = function(){
    vm.mydata.img.push('');
  }

  }
}());

Here is my form:

<div class="description">
    <h2>{{ show.mydata.title }}</h2>
    <p>{{ show.mydata.about }}</p>
    <p>{{ show.mydata.author }}</p>
    <p>{{ show.mydata.specs }}</p>
    <md-button class="md-raised md-primary">${{ show.mydata.price }}</md-button>
</div>


<form name="update-project-form" ng-submit="updateProject()" novalidate ng-show="auth.profile">
    <h1>Update Project</h1>

    <md-input-container class="md-icon-float md-block">
        <label>Project Name</label>
        <input ng-model="show.mydata.title" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block">
        <label>Author</label>
        <input ng-model="show.mydata.author" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block">
        <label>Description</label>
        <input ng-model="show.mydata.about" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block">
        <label>Specs</label>
        <input ng-model="show.mydata.specs" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block">
        <label>Price</label>
        <input ng-model="show.mydata.price" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block">
        <label>Link to buy</label>
        <input ng-model="show.mydata.link" type="text">
    </md-input-container>
    <md-input-container class="md-icon-float md-block" ng-repeat="img in show.mydata.img track by $index">
        <label>Image Url</label>
        <input ng-model="show.mydata.img[$index]" type="text">
    </md-input-container>

    <div layout-align="space-between none" layout="row">
        <ng-md-icon icon="add_circle" ng-click="addField()" size="40" style="fill: #56217c" type="button">Add Img Url Field</ng-md-icon>
        <ng-md-icon icon="remove_circle" ng-click="removeField()" size="40" style="fill: #56217c" type="button">Add Img Url Field</ng-md-icon>
        <md-button class="md-raised md-primary" id="submit" type="submit" value="Submit" ng-submit="updateProject()">Submit</md-button>
    </div>
</form>

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 31 خرداد 1395 ساعت: 2:17

صفحه بندی