我有一个json,我用它来填充angularjs中的表,并使表行可编辑以更新值,但如果值为空,那么我想恢复旧值。我试图使用临时变量来实现这一点,但是当我使用$scope
设置变量时,我得到的错误是:
$ scope.singleConfig.value未定义。
<tr ng-repeat="singleConfig in allConfigDatabase.data | filter:searchParameter|orderBy:orderByField:reverseSort" ng-style="{'background-color':(singleConfig.db == 'true'?'white':'gray')}">
<td >{{singleConfig.parameter}}</td>
<td >
<div ng-hide="editingData[singleConfig.id]"
style="padding-bottom: 10px">{{singleConfig.value}}</div>
<div ng-show="editingData[singleConfig.id]"
style="padding-bottom: 10px">
<input type="text" ng-model="singleConfig.value">
</div>
<span class="updateButton">
<button ng-hide="editingData[singleConfig.id]"
ng-click="modify(singleConfig);oldValue(singleConfig.value)" class="updateButton">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</span>
<button ng-show="editingData[singleConfig.id]"
ng-click="update(singleConfig);updateConfig(singleConfig.parameter,singleConfig.value,updateDatabaseCheck)">Save</button>
<input type="checkbox" id="updateCheckbox"
ng-model="updateDatabaseCheck" ng-show="editingData[singleConfig.id]"> <label
for="updateCheckbox" ng-show="editingData[singleConfig.id]">Save
in Database</label>
<button ng-show="editingData[singleConfig.id]"
ng-click="update(singleConfig);singleConfig.value=getOldValue();reset()">Close</button>
</td>
</tr>
控制器中的$scope.updateConfig = function(
updateParameter, updateValue,updateCheck) {
if (checkInputValidity(updateParameter,
updateValue)) {
if (updateCheck == true) {
addOrUpdateTable(
updateParameter,
updateValue, "true");
showNotification('**Your Value has been updated in database**','green',updateParameter,updateValue);
} else {
addOrUpdateTable(
updateParameter,
updateValue, "false");
showNotification('**Your Value has been updated in memory**','red',updateParameter,updateValue);
}
} else {
$scope.singleConfig.value=trackOldValue;//for this line getting an error
showNotification('**Your value field was empty**','red',null,null);
}
}