मैं अपने डेटा को संपादित करने के लिए मोडल का उपयोग करना चाहता हूं। मैं डेटा को मोडल उदाहरण में पास करता हूं। जब मैं ठीक क्लिक करता हूं तो मैं संपादित डेटा को $ scope में पास करता हूं। नियंत्रक को वापस ले लिया गया।
वहां मैं मूल $ स्कोप अपडेट करना चाहता हूं। किसी भी तरह से $ scope हालांकि अद्यतन नहीं करता है। मैं क्या गलत कर रहा हूं?
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;
});
};
};
मोडल नियंत्रक:
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');
};
};
मॉडल:
<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>
हेहे thx ye little typo, लेकिन समस्या हल नहीं करता है :-) – Tino