gpt4 book ai didi

angularjs - 无法在 ionic 中使用 ng-model 从模态检索值

转载 作者:行者123 更新时间:2023-12-04 17:08:39 24 4
gpt4 key购买 nike

This is my modal-profile.html


 <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>

This is my controller


.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);
});
}
})

I want to pass modelTitle,modelDescription parameters to 'ChatCtrl'controller. So I put two alerts in addDetail() funtion to check .but those are not showing any value.can any one help me? thanks in advance !

最佳答案

到目前为止,我已经使用了,而不是在 ng-model 中使用字符串尝试使用对象来绑定(bind)和检索值。就像是

HTML:

      <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="obj.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="obj.modelDescription" ng-Required="true" lose-focus-on-return></textarea>
</label>
</div>
</div>


<button class="button" ng-click="addDetail(obj)">ADD</button>

JS:
$scope.addDetail=function(object){

alert(object.modelTitle);
alert(object.modelDescription);
}

我通过堆栈引用 link here 得到了这个

关于angularjs - 无法在 ionic 中使用 ng-model 从模态检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31474152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com