0

I have a POST request within a function. I see the POST request gets the data correctly but for some reason the scope value doesn't get updated. The same request exsits at the start of controller where it works fine

$http.post('/api/v1/manual/create/edit?value='+$scope.edit,$scope.manual).success(function (data) {
            $modalInstance.dismiss('cancel');
            $scope.manual = data;   
            ManualService.setManual('');    
        }).error(function (data, status) {
            console.log('Error ' + data)
        })

POST response

[  
   {  
      "id":"5861f0ef4b282671e3da4bc8",
      "name":"Test",
      "version":"1.0.0",
      "details":"\u003cp\u003eTest\u003c/p\u003e",
      "createdOn":"Dec 26, 2016 8:41:19 PM",
      "testType":[  
         {  
            "name":"Mobile",
            "issues":"0",
            "scanned":false,
            "percentAudit":"0"
         },
         {  
            "name":"Database",
            "issues":"0",
            "scanned":false,
            "percentAudit":"0"
         },
         {  
            "name":"Web/Api",
            "issues":"0",
            "scanned":false,
            "percentAudit":"0"
         },
         {  
            "name":"Network",
            "issues":"0",
            "scanned":false,
            "percentAudit":"0"
         }
      ]
   }
]

In the above code value of $scope.manual doesn't get updated even if the response gets all the correct values.

je2tdam
  • 177
  • 1
  • 3
  • 15
  • What do you expect from data? Which value do you receive from data after the post? – Fals Dec 27 '16 at 20:54
  • Have you tried using `.then` and `.catch`? What happens when you log the values you get back? – TheSharpieOne Dec 27 '16 at 20:55
  • 1
    In this scenario, the `data` value is going to be the result of the XHR request, I think maybe you're looking for the `data.data` value... – YellowShark Dec 27 '16 at 20:56
  • I have added the POST response. I expect that this response value will get updated in "$scope.manual" so that I can see the changes on my view as well which is not happening. I did try data.data but without success – je2tdam Dec 27 '16 at 21:00
  • Where is this `$http.post` call being made from? a controller, or a service? and which version of angular? Also, you should really consider switching to `.then()`, since `.success()` is deprecated. – Claies Dec 27 '16 at 21:02
  • also, in this post response, `data` is an array, even though it only has one element; what does the binding look like? are you trying to bind to a single object? have you tried `data[0]`? – Claies Dec 27 '16 at 21:04
  • Yes single object. I did switch to .then() which doesn't work var url = `'/api/v1/manual/create/edit?value='+$scope.edit; $http({ method:'POST', url:url, data: $scope.manual }).then (function successCallback(response){ $scope.manual = response.data; $modalInstance.dismiss('cancel'); }, function errorCallback (response) { console.log(response); });` – je2tdam Dec 27 '16 at 21:16
  • so did `response.data[0]` not work, since you want the first object in the array returned? – Claies Dec 28 '16 at 00:52
  • Are you invoking the POST inside a `uib-bootstrap` modal? If that is the case, the POST is trying to set a property on a child scope. Try placing the data on the parent scope: `$scope.$parent.manual = data;`. – georgeawg Dec 28 '16 at 01:09
  • Also read: [Why are angular $http success/error methods deprecated? Removed from v1.6?](http://stackoverflow.com/a/35331339/5535245). – georgeawg Dec 28 '16 at 01:12
  • Yeah, we definitely need more code. There's a lot of relevant context missing here. Preferably the whole controller you're working with. – Aaron Pool Dec 28 '16 at 05:14

0 Answers0