为什么我的$ scope不会更新

时间:2016-02-09 19:21:26

标签: angularjs scope

我遇到了一个问题,我的$ scope拒绝从事件处理函数内部更新。 正在传递索引参数,并且数组实际上已被修改但屏幕未更新。 addFriend函数之外的$scope.people的其他引用完美地运行。 真的很难过!

myApp.controller('searchCtrl',function($scope,usrSvc,store){
  
  usrSvc.getUsers()
  .then(function success(users){
      if(users){
        $scope.people = users.data  
      }
  })

    
  $scope.search = function(searchterm){
    usrSvc.getUsers(searchterm)
    .then(function success(users){
      if(users){
        $scope.people = users.data  
      }
    })
  }

  $scope.addFriend = function(friend,index){
    usrSvc.addFriend(store.getId,friend._id)
    $scope.people.splice(0,index);
    console.log($scope.people.forEach(function(e){
      console.log(e)
    }))
    console.log(Array.isArray($scope.people)) //true
    console.log($scope.people)

 

  }


})

这是HTML:

<div class="centerText">
  <h3>{{person.username}}</h3>
  <p>{{person.fullname.join(' ')}}</p>
  <h5>{{person.email}}</h5>
  <button class="btn btn-success" ng-click="addFriend(person,$index)">Friend me</button>
</div>

0 个答案:

没有答案