Tôi muốn sử dụng phương thức để chỉnh sửa dữ liệu của mình. Tôi chuyển dữ liệu sang thể hiện phương thức. Khi tôi nhấn OK, tôi chuyển dữ liệu đã chỉnh sửa trong $ scope.selected trở lại bộ điều khiển.
Ở đó tôi muốn cập nhật phạm vi $ ban đầu. Bằng cách nào đó phạm vi $ không cập nhật mặc dù. Tôi đang làm gì sai?
var ModalDemoCtrl = function ($scope, $modal, $log) {
$scope.data = { name: '', serial: '' }
$scope.edit = function (theIndex) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
items: function() {
return $scope.data[theIndex];
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
// this is where the data gets updated, but doesn't do it
$scope.data.name = $scope.selected.name;
$scope.data.serial = $scope.selected.serial;
});
};
};
phương thức điều khiển:
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
name: $scope.items.name,
serial: $scope.items.serial
};
$scope.ok = function() {
$modalInstance.close($scope.selected);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
Modal:
<div class="modal-header">
<h3>{{ name }}</h3>
</div>
<div class="modal-body">
<input type="text" value="{{ serial }}">
<input type="text" value="{{ name }}">
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
Hehe thx ye ít lỗi đánh máy, nhưng không giải quyết được vấn đề :-) – Tino