Đây là tôi modal-profile.htmlKhông thể lấy giá trị từ phương thức sử dụng ng-mô hình trong ion
<ion-modal-view>
<form name="itemEdit" novalidate>
<ion-header-bar class="bar-positive fix-buttons">
<div class="row">
<a class="button " ng-click="closeModal()">Cancel</a>
<h1 class="title ">Diary</h1>
</div>
</ion-header-bar>
<ion-content has-bouncing="true">
<div class="row" ng-class="{'no-padding-top': !data.editItem}">
<div class="col">
<label class="item item-input large">
<input type="text" placeholder="Title" ng-model="modelTitle">
</label>
</div>
</div>
<div class="row description-row">
<div class="col">
<label class="item item-input text">
<textarea placeholder="Description" rows="5" ng-model="modelDescription" ng-Required="true" lose-focus-on-return></textarea>
</label>
</div>
</div>
<button class="button" ng-click="addDetail()">ADD</button>
<div class="row charity-row">
<div class="col col-10 vert-center">
<div class="charity large"></div>
</div>
</div>
</ion-content>
</form>
</ion-modal-view>
Đây là bộ điều khiển của tôi
.controller('ChatsCtrl', function($scope,$ionicModal, Chats,$state,$cordovaSQLite) {
$scope.chats = Chats.all();
$scope.remove = function(chat) {
Chats.remove(chat);
}
$ionicModal.fromTemplateUrl('templates/modal-profile.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal){
$scope.modal = modal
})
$scope.openModal = function(){
$scope.modal.show();
}
$scope.addDetail = function(){
alert($scope.modelTitle);
alert($scope.modelDescription);
var db = $cordovaSQLite.openDB("diary.db");
var query = "INSERT INTO details (title, description) VALUES (?,?)";
$cordovaSQLite
.execute(db, query, [$scope.modelTitle, $scope.modelDescription])
.then(function(res){
alert("success");
}, function(err){
alert(err);
});
}
})
Tôi muốn chuyển thông số modelTitle, modelDescription vào 'ChatCtrl'controller. Vì vậy, tôi đặt hai cảnh báo trong addDetail() chức năng để kiểm tra. Nhưng những người không hiển thị bất kỳ giá trị. Có thể bất kỳ một giúp tôi? cảm ơn trước!
Hãy thử đặt console.log ($ phạm vi) và xem các khách sạn có được định nghĩa khi bạn gọi hàm. –
Cảm ơn rất nhiều vì đã bình luận. Tôi đã tìm ra một giải pháp cho điều đó. – HRCJ
http://codepen.io/ionic/pen/gblny – HRCJ