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

标签 angularjs cordova ionic

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/

相关文章:

angularjs - 在自定义指令中禁用 ngClick 事件处理

html - AngularJS 文件上传到后端 Express 服务器

select - angularjs - 如何基于原始模型而不是模型填充 html 选择元素选项

移动浏览器中的 Javascript UTC 日期问题

cordova - Phonegap 原生通知声音

angularjs - 在 Ionic 中创建和显示 pdf

angularjs - 在 AngularJS 和 Ionic 上渲染列表之前等待异步数据

javascript - 如何在 Javascript 中深度克隆 XMLDocument 对象?

cordova - ionic 平台事件不起作用

css - 字体不适用于 ionic/phonegap 应用程序