2016-05-31 38 views
1

我在執行PUT請求後無法更新我的ng-repeat列表。服務工作正常。如何在http請求後更新ng-repeat列表

controller.js

teamData.updateTeam(team.id, teamObj, function(res) { 
         console.log('Success'); 
        }); 

service.js

teamService.updateTeam = function(teamId, param, callback) { 
      var req = { 
      method: 'PUT', 
      url: '/team' + teamId, 
      headers: { 
       'Content-Type': 'application/json' 
      }, 
      'data': param 
      }; 
      return $http(req).then(function(res){ 
      callback(res); 
      }, function(err){ 
      callback(err); 
      }); 
     }; 

teamRoute.js

app.put('/team/:id', function(request, response) { 
    var options = { 
     host: reqParam.hostFramework, 
     path: reqParam.path + '/team/' + request.params.id, 
     method: 'PUT', 
     headers: { 
      'token': reqParam.token, 
      'Content-Type': 'application/json', 
      'Content-Length': Buffer.byteLength(JSON.stringify(request.body)) 
     } 
    }; 
    var resString = ''; 
    var req = https.request(options, function(res) { 
     res.setEncoding('utf8'); 
     res.on('data', function(d) { 
      resString += d; 
     }); 
     res.on('end', function() { 
      response.send(resString); 
     }); 
    }); 
    req.write(JSON.stringify(request.body)); 
    req.end(); 
}); 

team.html

<div ng-repeat="team in teamData"> 
    <h2>{{team.name}}</h2> 
    .... 
</div> 

我的目標是在發出PUT請求(不刷新頁面)後立即更新ng-repeat列表。我怎樣才能實現它?

+1

你應該只能夠推任何你想進入你的請求過程中重複什麼之前/後/。 –

+0

'ngRepeat'部分在哪裏?如何在請求後更新項目?我們應該猜測? –

+0

添加teamRoute.js和team.html文件 – Laurynas

回答

2

將其指定回模型。例如,如果你的NG-重複是在$ scope.item則:

return $http(req).then(function(res){ 
     callback(res); 
     $scope.item = res 
     }, function(err){ 
     callback(err); 
     }); 
+0

打破綁定?怎麼樣?這正是綁定的工作原理。 – Wainage

+0

它不會更新我的team.html。我必須重新加載頁面才能看到更改 – Laurynas