Angularjs 如何发布ng重复对象数据?我试过这种方法,但不起作用
如何发布ng重复对象数据?我试过这种方法,但不起作用Angularjs 如何发布ng重复对象数据?我试过这种方法,但不起作用,angularjs,angular-ui-router,Angularjs,Angular Ui Router,如何发布ng重复对象数据?我试过这种方法,但不起作用 <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
<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>
从:
在您的情况下,您缺少回调函数:
$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');
});
{{item}}
拯救
如上所述更改您的ng型号
使用mc.items代替self.items
// 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');
});
<body ng-controller="mainCtrl as MC">
<div>
<div ng-repeat="(item,value) in MC.items">
{{item}} <input type="text" ng-model="MC.items[item]"/>
</div>
</div>
<button ng-click="MC.submitMe()">Save</button>
Change your ng-model as above