如何访问NG-模型值在弹出的模式控制器的角度? [英] How to access ng-model value in controller of popup model in angular?

查看:122
本文介绍了如何访问NG-模型值在弹出的模式控制器的角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从控制器内访问ngModel,但这里的ngModel在弹出的输入字段定义。我要访问控制器的数量和名称值。请注意,这整个code是模型弹出。

模型code

 <离子态 - 视图>
    <离子标题栏>
        < H1类=标题>项目详情及LT; / H1>
    < /离子头吧>
    <离子含量填充=真正的>
        <形式NG提交=的addItem()>
            < D​​IV CLASS =名单列表的插图>
                <标签类=逐项输入>
                    <跨度类=输入标签>名称和LT; / SPAN>
                    <输入类型=文本名称=名字吴模型=名>
                < /标签>
                <标签类=逐项输入>
                    <跨度类=输入标签>及数量LT; / SPAN>
                    <输入类型=数字NAME =数量NG模型=数量>
                < /标签>
                < D​​IV CLASS =填充项目文本中心>
                    <按钮类=按钮按钮暗>添加到购物车< /按钮>
                    <一类=按钮按钮主见NG点击=closeModal()>取消< / A>
                < / DIV>
            < / DIV>
        < /表及GT;
    < /离子含量>
< /离子态 - 视图>

控制器code

  .controller('GuestDetailsCtrl',函数($范围){
    $ scope.addItem =功能(){
        警报($ scope.name);
        警报($ scope.qty);
    };
});


解决方案

您可以尝试给PARAMS像这样的功能:

 <离子态 - 视图>
<离子标题栏>
    < H1类=标题>项目详情及LT; / H1>
< /离子头吧>
<离子含量填充=真正的>
    <形式NG提交=的addItem(PARAMS)>
        < D​​IV CLASS =名单列表的插图>
            <标签类=逐项输入>
                <跨度类=输入标签>名称和LT; / SPAN>
                <输入类型=文本名称=名字吴模型=params.name>
            < /标签>
            <标签类=逐项输入>
                <跨度类=输入标签>及数量LT; / SPAN>
                <输入类型=数字NAME =数量NG模型=params.qty>
            < /标签>
            < D​​IV CLASS =填充项目文本中心>
                <按钮类=按钮按钮暗>添加到购物车< /按钮>
                <一类=按钮按钮主见NG点击=closeModal()>取消< / A>
            < / DIV>
        < / DIV>
    < /表及GT;
< /离子含量>

和在你的控制器:

  .controller('GuestDetailsCtrl',函数($范围){
      $ scope.addItem =功能(PARAMS){
          警报(params.name);
          警报(params.qty);
      };
  });

I want to access an ngModel from within a controller, but here the ngModel is defines in a popup input field. I want to access the qty and name values in controller. Note that this whole code is model popup.

Model code

<ion-modal-view> 
    <ion-header-bar>
        <h1 class="title">Item Details</h1>
    </ion-header-bar>
    <ion-content padding="true">
        <form ng-submit="addItem()">
            <div class="list list-inset">
                <label class="item item-input">
                    <span class="input-label">Name</span>
                    <input type="text" name="name" ng-model="name">
                </label>
                <label class="item item-input">
                    <span class="input-label">Qty</span>
                    <input type="number" name="qty" ng-model="qty">
                </label>
                <div class="padding item text-center">
                    <button class="button button-dark">Add To Cart</button>
                    <a class="button  button-assertive" ng-click="closeModal()">Cancel</a>            
                </div>
            </div>
        </form>
    </ion-content>
</ion-modal-view>

Controller code

.controller('GuestDetailsCtrl', function($scope){
    $scope.addItem = function() {
        alert($scope.name);
        alert($scope.qty);
    }; 
});

解决方案

You could try to give params in the function like this :

<ion-modal-view> 
<ion-header-bar>
    <h1 class="title">Item Details</h1>
</ion-header-bar>
<ion-content padding="true">
    <form ng-submit="addItem(params)">
        <div class="list list-inset">
            <label class="item item-input">
                <span class="input-label">Name</span>
                <input type="text" name="name" ng-model="params.name">
            </label>
            <label class="item item-input">
                <span class="input-label">Qty</span>
                <input type="number" name="qty" ng-model="params.qty">
            </label>
            <div class="padding item text-center">
                <button class="button button-dark">Add To Cart</button>
                <a class="button  button-assertive" ng-click="closeModal()">Cancel</a>            
            </div>
        </div>
    </form>
</ion-content>

And in your controller :

   .controller('GuestDetailsCtrl', function($scope){
      $scope.addItem = function(params) {
          alert(params.name);
          alert(params.qty);
      }; 
  });

这篇关于如何访问NG-模型值在弹出的模式控制器的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆