Ionic之数据绑定ng-model

ionic 完美的融合下一代移动框架,ionic 基于Angular语法,支持 Angularjs 的特性。但是我在开发的时候,遇到了坑。因为之后用的就是angularjs,so 理所当然的以为代码应该时这样的写:

<div class="item item-input">
            <span>手 机 号:</span>  
            <input type="text" ng-model="phone">
        </div>

        <div class="item item-input">
            <span>验 证 码:</span>  
            <input type="text" ng-model="code">
            <button class="button button-calm" ng-click="ionGetCode()">获取验证码</button>
        </div>
        <div class="item item-input codeSuccess" >
            <span>新 密 码:</span>  
            <input type="text" ng-model="newPwd">
        </div>
        <div class="item item-input codeSuccess" >
            <span>确认密码:</span>  
            <input type="text" ng-model="confirm">
   </div>

  在页面:

{{phone}} //就可以直接获取你输入的值

但是在js中:

 console.log("userName:"+$scope.userName);
 console.log("$scope.phone:"+$scope.phone);  //无法获取输入的值

之后查了官网文档,也查了很多资料,才知道这样写也不行的,详细解释可以去官网http://ionicframework.com/docs/

<div class="item item-input">
            <span>手 机 号:</span>  
            <input type="text" ng-model="$parent.phone">
        </div>

        <div class="item item-input">
            <span>验 证 码:</span>  
            <input type="text" ng-model="$parent.code">
            <button class="button button-calm" ng-click="ionGetCode()">获取验证码</button>
        </div>
        <div class="item item-input codeSuccess" >
            <span>新 密 码:</span>  
            <input type="text" ng-model="$parent.newPwd">
        </div>
        <div class="item item-input codeSuccess" >
            <span>确认密码:</span>  
            <input type="text" ng-model="$parent.confirm">
        </div>

  

转载于:https://www.cnblogs.com/liziyou/p/6489289.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值