如何发布ng-repeat对象数据?我试过这种方式,但没有工作

时间:2016-01-20 11:24:15

标签: angularjs angular-ui-router

如何发布ng-repeat对象数据?我试过这种方式但没有工作。

<body ng-controller="mainCtrl as MC">
<div>
    <div ng-repeat="(item,value) in MC.items">
        {{item}} <input type="text" ng-model="value"/>
    </div>
</div>
<button ng-click="MC.submitMe()">Save</button>

控制器:

mc.items = {prompt: 'prompt 1', value: 'value 1'};

mc.submitMe = function(){
    var url = 'http://serverUrl';

    //sample post code:
    //$http.post(url, self.items);

    //debug:
    alert('post data to ' + url + '\n' + JSON.stringify(mc.items));
};

2 个答案:

答案 0 :(得分:0)

来自AngularJs Docs

// Simple GET request example:
$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

在你的情况下你缺少回调函数:

$http.post(url, mc.items).then(function successCallback(response) {
  alert('post data to ' + url + '\n' + JSON.stringify(mc.items));

}, function errorCallback(response) {
  alert('post failed');
});

答案 1 :(得分:0)

playing