weixin_33728268 2014-04-15 04:34 采纳率: 0%
浏览 6

将结果推送到数据库

I am new to AngularJS and am trying to push the property value of an object when it is changed in my app. For instance:

List 1
<ul>
  <li ng-repeat="item in items | filter : {selected: false}">
    {{ item.name }}
    <a href="#" ng-click="move(item)">move</a>
  </li>
</ul>

List 2
<ul>
  <li ng-repeat="item in items | filter : {selected: true}">
    {{ item.name }}
    <a href="#" ng-click="move(item)">move</a>
  </li>
</ul>

So in this app, when I click "move" it changes the selected property to true or false. However in the DB this is not reflected. How can I post these as AJAX requests to achieve persistence?

  • 写回答

1条回答 默认 最新

  • csdn产品小助手 2014-04-15 05:13
    关注

    You can use $http to make an ajax call before changing the item's state. Something like...

    $scope.move = function(item) {
        var newState = !item.selected;
        $http.post(someurl, item).success(function() {
            item.selected = newState;
        });
    };
    
    评论

报告相同问题?