angular.js - angularJs select绑定的model取不到值
伊谢尔伦
伊谢尔伦 2017-05-15 16:54:58
0
3
503

页面
<ion-view view-title="筛选条件">

<ion-nav-buttons side="left">
    <a class="button button-clear" ng-click="backToPhoneCall()"><i class="icon ion-ios-arrow-left"></i>电话量排行</a>
</ion-nav-buttons>
<ion-nav-buttons side="right">
    <a class="button button-clear" ng-click="saveParam()">应用</a>
</ion-nav-buttons>

<ion-content>
    <p class="list" ng-init="initPage()">
        <p class="item item-pider" style="font-size: 17px;">时间范围{{selected}}
        </p>

        <p class="item">
            <select ng-model="selected">
             <option>本季度</option>
                <option>本月</option>
                <option>本周</option>
            </select>
        </p>
        <p class="item item-pider" style="font-size: 17px;">查看范围
        </p>
        <p class="item" ng-click="goToAddUser()">

        </p>
    </p>
</ion-content>

</ion-view>

控制器
appCtrls.controller('chooseParamPhoneCallCtrl', function ($scope, $state, $stateParams, localStorageService, boardService) {

$scope.initPage=function(){
    $scope.selected="";
}
$scope.backToPhoneCall = function () {
    $state.go("tab.crm-viewCrmBoardPhoneCalls");
}
$scope.goToAddUser = function () {
    var paramChoosePhoneCall = {term: $scope.selected};
    console.debug("paramChoosePhoneCall-->>>" + angular.toJson(paramChoosePhoneCall));
    //localStorageService.setLocalStorage("paramChoosePhoneCall",paramChoosePhoneCall);
}

})

如代码所示,页面加载之时初始化selected,然后将selected绑定到select,每次改变选择的内容{{selected}}中能正确显示改变后的内容,但是当点击查看范围下面的p触发goToAddUser后,在里面$scope.selected取到的不是选择后的内容,而是初始化之时赋得空值。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(3)
迷茫
<select ng-model="selected">
    <option>本季度</option>
    <option>本月</option>
    <option>本周</option>
</select>
<button ng-click="btnClick(selected)">event</button>

后台

$scope.btnClick = function (selected) {
    // do sth
}

这样就好了
前台把值扔到方法里 就没问题了

过去多啦不再A梦
<select
      class="small"
      ng-model="selects[0]"
      ng-change="showSelect(select)"
      ng-options="r.name for r in selects">
  </select>

controller中

$scope.selects = [{id:'0',name:'本季度'},{id:'1',name:'本月'},{id:'2',name:'本周'}];
我想大声告诉你

雷雷

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板