我想知道如何将对象存储到范围中。我不确定我的语法是否正确。我的目标是在此编辑页面上设置数据绑定,然后将编辑的对象存储在范围上。但数据不会被推入阵列
$scope.editedRecord = function (editedExpensesInfo) {
$scope.tempData.push(editedExpensesInfo)
}
$scope.save = function() {
WebApi.editData($scope.tempData);
};
TempData是我服务中的数组。
angular.module('app')
.factory('WebApi', function () {
var tempData = [];
return{
editData: function (data) {
return tempData = data;
},
}
}
这是我的编辑表格
<!--Ion-nav-header-bar-->
<ion-nav-bar class="bar bar-header bar-positive">
<ion-nav-back-button class="button-clear" ng-click="myGoBack()">
<i class="ion-arrow-left-c"></i> Back
</ion-nav-back-button>
</ion-nav-bar>
<!--ion-nav-side-menu-button-->
<!--<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>-->
<!--Content for Expenses page-->
<ion-content has-header="true" padding="true">
<div ng-controller="editExpensesDetailCtrl" ng-model="editedExpensesInfo">
<form name="editExpensesDetailform" ng-submit="editedRecord(editedExpensesInfo)>
<label class="item item-input ">
<b class="input-label">Owner:</b>
{{data.owner}}
</label>
<label class="item item-input">
<b class="input-label">Receipt Date:</b>
<!--{{data.modifiedDate | date: "yyyy-MM-dd"}}-->
<input style="margin-left: 20%;" ng-model="editedExpensesInfo.newDate" type="date" placeholder="Date" required>
</label>
<!--<label class="item item-input">
<b class="input-label">Claim Type:</b>
{{data.claimType}}
</label>-->
<label class="item item-input item-select">
<b class="input-label">Claim Type:</b>
<select ng-model="editedExpensesInfo.newClaimType" required>
<option value="" title="Select Claim" selected disabled>Claim Type</option>
<option ng-repeat="claim in claimType" value="{{claim.value}}"
ng-selected="{{claim.value== claimType}}">
{{claim.value}}
</option>
</select>
</label>
<br />
<!--Remarks Textfield-->
<br />
<b>Remarks:</b>
<br />
<label>
<!--<span style="margin-bottom:auto"> {{data.description}}</span>-->
<textarea ng-model="editedExpensesInfo.newDescription" rows="6" cols="50" placeholder="Your remarks..." style="resize:none; border:solid 1px;"></textarea>
</label>
</form>
<br />
<a class="button button-positive" ng-click="save()">Save</a>
</div>
</ion-content>
</ion-view>
答案 0 :(得分:0)
您的控制器功能editedRecord
未被调用。
查看ngSubmit文档。
您需要添加提交按钮。例如:
<input type="submit" id="submit" value="Save Edit" />
希望这有帮助。