javascript - Why doesn't this two way data binding work? -


i have controller. whenever try bind $scope.things received json server, view wont update. in fact, if left push(newthing) , uncomment calls getallthings(), view display data and, in less second, remove it.

the problem is: in server side (morgan running node , mongodb), i'm printing out json object before passed client , object correct, have latest created object.

i'm willing use push instead of making request server fetch data, i'm upset topic. interesting thing second, third , consequent calls insertthing() update view. made feel kind of clueless. can provide more code if needed.

controller:

$scope.insertthing= function(newthing){     $scope.things.push(newthing);     $http.post('http://localhost:8080/things', newthing)     .then(function(res){         //$scope.getallthings();         delete $scope.newthing;     }, function(res){      });     //$scope.getallthings();     };  $scope.getallthings = function(userdpt){     $http.post('http://localhost:1234/things/dpt/', {userdpt: userdpt})     .then(function(res){         $scope.things = res.data;     }, function(res){      }); }; 

node server mongoose:

app.post('/things/dpt', function(req, res){ var department = req.body.dpt; var things= {}; ticketmodel.find({ fromdpt: department},      function(err,obj){         res.json(obj);     }); }); 

markup:

<tr ng-repeat="thing in things">   <td> {{ thing.todpt}} </td>   <td> {{ thing.status }}</td>   <td> {{ thing.deadline }}</td>   <td><button class="btn close" data-ng-click="deletething(thing._id)">&times;</button></td> </tr>  

well, long time ago.

all code refactored. problem assyncronous behavior of javascript. sometimes, getallthings() function finish before delete line , new fetched data vanish after being received.

the way around problem add callback after http request.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -