Angularjs 无法从清单值中获取值

Angularjs 无法从清单值中获取值,angularjs,checklist-model,Angularjs,Checklist Model,这是我的密码 标记: <div ng-repeat="product in Products" ng-if="$index % 3 == 0" class="row"> <div class="col-xs-4"> <md-checkbox checklist-model="user.roles" checklist-value="{{Products[$index]}}"><span>{{Products[$index]

这是我的密码

标记:

<div ng-repeat="product in Products" ng-if="$index % 3 == 0" class="row">
    <div class="col-xs-4"> 
        <md-checkbox checklist-model="user.roles" checklist-value="{{Products[$index]}}"><span>{{Products[$index].Name}}</span></md-checkbox>
    </div>
    <div class="col-xs-4"> 
        <md-checkbox checklist-model="user.roles" checklist-value="{{Products[$index]}}"><span>{{Products[$index+1].Name}}</span></md-checkbox>
    </div>
    <div class="col-xs-4"> 
        <md-checkbox checklist-model="user.roles" checklist-value="{{Products[$index]}}"><span>{{Products[$index+2].Name}}</span></md-checkbox>
    </div>
</div>
<button ng-click="checkAll()" style="margin-right: 10px">Check all</button>
<button ng-click="uncheckAll()" style="margin-right: 10px">Uncheck all</button>
<button ng-click="checkFirst()">Check first</button>
<button ng-click="setToNull()" ng-if="setToNull">Set to null</button>
var pramiseGet = angularService.GetProducts();


       pramiseGet.then(function (pl) {
            $scope.Products = pl.data;
           console.log($scope.Products);
        },

    function (errorPl) {
        $log.error("Error", errorPl);
    });

$scope.roles = {};
    $scope.user = {};
    $scope.sendingID = {};
    $scope.checkAll = function () {
        $scope.user.roles = angular.copy($scope.Products);
    };
    $scope.uncheckAll = function () {
        $scope.user.roles = [];
    };
    $scope.checkFirst = function () {
        $scope.user.roles.splice(0, $scope.user.roles.length);
        $scope.user.roles.push('guest');
    };
我想做的是,当我选中复选框时,我需要在代码所在的下面div中看到数据

<div class="col-xs-12 col-sm-6">
    <h3>user.roles</h3>
    <pre>{{user.roles|json}}</pre>
</div>

用户角色
{{user.roles | json}}

目前,我没有在上面的div中查看任何数据。任何帮助检查以下代码,这将解决您的问题

查看

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.Products = [{name:'Product 1'},{name:'Product 2'},{name:'Product 3'}];
    $scope.checkAll = function(){
       $scope.Products.forEach(function(e){e.checked = true})
    }
    $scope.uncheckAll = function(){
       $scope.Products.forEach(function(e){e.checked = false})
    }
    $scope.checkFirst= function(){
       $scope.Products[0].checked = true
    }
    $scope.checkAll = function(){
       $scope.Products.forEach(function(e){e.checked = true;})
    }
    $scope.setToNull = function(){
       $scope.Products.forEach(function(e){e.checked = null;});
    }
});
var-app=angular.module(“myApp”,[]);
app.controller(“myCtrl”,函数($scope){
$scope.Products=[{
名称:“产品1”,id:1
}, {
名称:“产品2”,id:1
}, {
名称:“产品3”,id:1
}, {
名称:“产品4”,id:1
}, {
名称:“产品5”,id:1
}, {
名称:“产品6”,id:1
}, {
名称:“产品7”,id:1
}, {
名称:“产品8”,id:1
}, {
名称:“产品9”,id:1
}, {
名称:“产品10”,id:1
}, {
名称:“产品11”,id:1
}, {
名称:“产品12”,id:1
}];
$scope.selectedProducts=[];
$scope.updateSelectedProducts=函数(){
$scope.selectedProducts=$scope.Products.filter(函数(e){返回e.checked});
};
$scope.checkAll=function(){
$scope.Products.forEach(函数(e){
e、 选中=真
});
$scope.updateSelectedProducts();
}
$scope.uncheckAll=函数(){
$scope.Products.forEach(函数(e){
e、 选中=错误
});
$scope.updateSelectedProducts();
}
$scope.checkFirst=函数(){
$scope.Products[0]。选中=true;
$scope.updateSelectedProducts();
}
$scope.checkAll=function(){
$scope.Products.forEach(函数(e){
e、 选中=正确;
});
$scope.updateSelectedProducts();
}
$scope.setToNull=函数(){
$scope.Products.forEach(函数(e){
e、 选中=空;
});
$scope.updateSelectedProducts();
}
});


所选产品:{{selectedProducts}}

{{Products[$index].name} {{Products[$index+1].name} {{Products[$index+2].name} 全部检查 全部取消选中 先检查 设置为空





checklist model=“user.roles”模型名称不正确提供一个演示小提琴将真正有助于解决您的问题。你的代码应该能用。@jimbroosism是的。但是
checkall
功能应该可以工作correctly@Jimbrooism对此我很抱歉。这在我的原始代码中是正确的。这个代码有效。但问题是我无法得到清单的值。我从web api获取数据,因此fiddle代码希望能够显示我遇到的确切问题您可以在
$scope.Products=datas
中通过api返回的数据创建一个fiddle a。问题是它确实与数组一起工作。我的问题是它不适用于范围object@TharinduSenanayake,产品是范围对象。请详细说明您从何处获取产品列表的问题。我正在从web api控制器传递列表
var pramiseGet=angularService.GetProducts();然后(函数(pl){$scope.Products=pl.data;console.log($scope.Products);},函数(errorPl){$log.error(“error”,errorPl);})这是控制器code@TharinduSenanayake,检查$scope.Products结果。它应该是一个产品对象列表,每个产品对象中都有一个名称变量。是的。我怎样才能让它工作呢。它也有ID属性,谢谢@VenuprasadHS,你让我开心。非常感谢你
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.Products = [{name:'Product 1'},{name:'Product 2'},{name:'Product 3'}];
    $scope.checkAll = function(){
       $scope.Products.forEach(function(e){e.checked = true})
    }
    $scope.uncheckAll = function(){
       $scope.Products.forEach(function(e){e.checked = false})
    }
    $scope.checkFirst= function(){
       $scope.Products[0].checked = true
    }
    $scope.checkAll = function(){
       $scope.Products.forEach(function(e){e.checked = true;})
    }
    $scope.setToNull = function(){
       $scope.Products.forEach(function(e){e.checked = null;});
    }
});