Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角离子开关群_Javascript_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 角离子开关群

Javascript 角离子开关群,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我用angular和ionic编写了一组phonegap应用程序的切换。基本设置是这样的;html: <div ng-controller="LoginCtrl"> <h2 class="title">Items</h2> <ion-toggle ng-repeat="item in riderList" ng-model="selectedRider" ng-checked="item.checked"

我用angular和ionic编写了一组phonegap应用程序的切换。基本设置是这样的;html:

<div ng-controller="LoginCtrl">
<h2 class="title">Items</h2>
    <ion-toggle ng-repeat="item in riderList"
        ng-model="selectedRider"
        ng-checked="item.checked"
        ng-change=" updateRider();"
        data-rider-id="{{ item.id }}"
        >
        {{ item.text }}
    </ion-toggle>
<button class="button button-full button-positive" id="zpass-logout">
  Logout
</button>
</div>

似乎无法访问已更改的切换的id和状态。正确的方法是什么?

将ng模型设置为“已选中”属性,以便无论是否选中该选项,该模型都会更新。移除选中的ng,因为ng模型将处理它。为了访问选中的项,只需在ng change上传递
更新程序
函数表达式中的
,然后访问它

i、 e:

angular.module('zpassApp')
  .controller('SettingsCtrl', ['$scope', '$http', '$rootScope', '$location',
    function($scope, $http, $rootScope, $location) {

    $scope.riderList = [];

    $scope.addRider = function(name, id, active) {
        $scope.riderList.push( { "text" : name, "checked" : active , "id" : id});
        $scope.$apply();
    };

    $scope.updateRider = function() {
        console.log("in update rider how do I get the item.id!?" );
        // I expect this to be selectedRider.id, but that is undefined
        // in jquery would be $(this)..data('id');
    }

    function getRidersFromDB() {
        // this just queries db an populates, works fine...
    }
 <ion-toggle ng-repeat="item in riderList"
    ng-model="item.checked"
    ng-change=" updateRider(item);">
    {{ item.text }}
</ion-toggle>
$scope.updateRider = function(item) {
  //console.log(item.id, item.checked);
}