2016-11-18 3 views
0

dbに値を挿入することができますが、dbからフェッチする際に値を確認できませんでした。ヘルプ。ありがとう。db(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> 

私の値は、角度の方法を使用している場合、ng-modelを使用し、

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

答えて

2

代わりvalueのまず第一に、、として、DBに格納されます。

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はplsは私のNG-クラスを編集することができます.... – MMR

+0

編集してください。今すぐご確認ください。 – Sravan

+0

@nlr_p、それをチェックしましたか? – Sravan

関連する問題