2016-11-18 37 views
0

我能夠插入值到數據庫根據檢查,但我沒有檢查數據從db ..獲取時可以檢查任何一個給我一些help.Thanks。如何檢查基於存儲在分貝(Angularjs)值的複選框

我的模板,

<div class="btn-group col-xs-4 nopadding" ng-repeat="type in vm.bussinesstypeoptions" data-toggle="buttons"> 
    <label class="col-xs-12 btn btn-white" ng-click="toggleSelection(type)" ng-class="{'active': type == checkvalue.name }"> 
<input type="checkbox" name="selectbox" value="type" ng-checked="vm.selection.indexOf(checkvalue.name) > -1" required> {{type}} 
    </label> 
</div> 

我在值存儲在數據庫作爲,

所有的
"business_type" : [ 
    "Education Consultant", 
    "Guardianship", 
    "Hotel/Home-Stay" 
], 

回答

2

首先,取而代之的value,使用角的方式,當使用ng-model

然後將ng-checked設置爲ng-model的值。

ng-model="type" and ng-checked="type"

這裏是解決片段:

var app = angular.module('myApp', []); 
 
app.controller('myCtrl', function($scope) { 
 

 
$scope.bussinesstypeoptions = ['Education Consultant', 'Ticket/Travel', 'Hotel/Home-Stay', 'Guardianship', 'Visa/Solicitors', 'Others']; 
 

 
$scope.object = {} 
 
$scope.business_type = [ 
 
    "Education Consultant", 
 
    "Guardianship", 
 
    "Hotel/Home-Stay" 
 
] 
 

 

 
for(i = 0;i < $scope.business_type.length; i++) 
 
{ 
 

 
$scope.object[$scope.business_type[i]] = true; 
 
console.log($scope.object) 
 
    
 
} 
 
});
<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
<body> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 

 
<div class="btn-group col-xs-4 nopadding" ng-repeat="type in bussinesstypeoptions" data-toggle="buttons"> 
 
    <label class="col-xs-12 btn btn-white" ng-click="toggleSelection(type)" ng-class="{'active': object.type}"> 
 
<input type="checkbox" name="selectbox" ng-checked="object[type]" required ng-model="type"> {{type}} 
 
    </label> 
 
</div> 
 

 
</div> 
 

 
</body> 
 
</html>

Here is a fiddle of it

+0

u能請編輯我納克級.... – MMR

+0

編輯,請現在檢查。 – Sravan

+0

@nlr_p,檢查它? – Sravan

相關問題