search

Home  >  Q&A  >  body text

angular.js - The model bound by angularJs select cannot get the value

Page
<ion-view view-title="Filter Conditions">

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

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

})

As shown in the code, selected is initialized when the page is loaded, and then bound to select. Each time the selected content is changed, {{selected}} can correctly display the changed content, but when clicking below the view range After p triggers goToAddUser, what $scope.selected gets inside is not the selected content, but the null value assigned during initialization.

伊谢尔伦伊谢尔伦2840 days ago552

reply all(3)I'll reply

  • 迷茫

    迷茫2017-05-15 16:56:58

    <select ng-model="selected">
        <option>本季度</option>
        <option>本月</option>
        <option>本周</option>
    </select>
    <button ng-click="btnClick(selected)">event</button>

    Backstage

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

    That’s fine
    If the frontend throws the value into the method, then there will be no problem

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 16:56:58

    <select
          class="small"
          ng-model="selects[0]"
          ng-change="showSelect(select)"
          ng-options="r.name for r in selects">
      </select>

    in controller

    $scope.selects = [{id:'0',name:'本季度'},{id:'1',name:'本月'},{id:'2',name:'本周'}];

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-15 16:56:58

    <select name="type" id="selSubtype" class="form-control"  ng-model="article.subtype" style="min-width:120px;"  required>
        <option  ng-repeat="asubtype in subtypes | filter:subfilter"  ng-value="asubtype.id" ng-selected="asubtype.id == article.subtype" >{{asubtype.name}}</option>
    </select>

    reply
    0
  • Cancelreply