从集合更新特定范围

时间:2014-07-24 03:14:33

标签: angularjs angularjs-scope

我收集了一些信息,例如:

$scope.messages = [];
myMsgService.getAll().then(function (messages) {
     $scope.messages.push(messages);//array of objects - this is my collection    
});

我的HTML:

  <div data-ng-controller="MessageController" data-ng-repeat="message in messages" class="message">...</div>

我有10条消息,如果我想在我的数据库中更新它之后只更新一条消息(在我的html中),我将如何做到这一点?想象一下,我点击一条消息,编辑它,在我的数据库中更新,之后我只想在我的html中更新这条消息,我将如何做到这一点?

1 个答案:

答案 0 :(得分:1)

如果这有帮助,只需创建一个小提琴

angular.module('myapp',[])
  .controller('MessageController',function($scope){
     $scope.messages=['one','two','three','four','five'];
      $scope.valChange=function(index,msg){
       //just for test. logic to store in db
        $scope.messages[index]=msg;
        console.log($scope.messages);
      }
  });

http://jsfiddle.net/S2UFK/1/