Reputation: 542
$http.get('***').success(function(data, status,response)
{
$scope.items=data;
var getdata=JSON.stringify(data.D_Services);
console.log(getdata);
});
im getting in console
D_Services: "Wash,Tyres,Spares,Accessories";
please any one help me out
<div ng-controller="Test1Controller" data-ng-init="loadservice()">
<div ng-repeat="item in items">
<input type="checkbox" ng-model="item.SELECTED" ng-true-value="'Y'" ng-false-value="'N'"/> {{item.D_Services}}
</div>
</div>
I need answer like this please any one help me out
now im getting
Upvotes: 1
Views: 433
Reputation: 4091
You declare your "array" as a String.
Make it an Array instead:
$scope.items = ['Wash', 'Tyres', 'Spares', 'Accessories'];
If you need to keep it as a String, use .split()
:
<div ng-repeat="item in items.split(',')">
Upvotes: 5
Reputation: 3944
HTML
<div ng-controller="Test1Controller" data-ng-init="loadservice()">
<div ng-repeat="item in items">
<input type="checkbox" ng-model="item.SELECTED" ng-true-value="'Y'" ng-false-value="'N'"/> {{item}}
</div>
</div>
In controller
$scope.items=["Wash","Tyres","Spares","Accessories"];
Fiddle for better understanding http://jsfiddle.net/sykxr2ex/
plunker If you want to use services http://plnkr.co/edit/Y0Y5o2?p=preview
Upvotes: 0
Reputation: 2124
Because you want to be able to set a selected flag for each string, you need a list of objects.
$scope.items=[
{title: "Wash", selected: false},
{title: "Tyres", selected: false},
{title: "Spares", selected: false },
{title: "Accessories", selected: false}" ];
Then you can use the following code.
<div ng-controller="Test1Controller" data-ng-init="loadservice()">
<div ng-repeat="item in items">
<input type="checkbox" ng-model="item.selected" ng-true-value="'Y'" ng-false-value="'N'"/> {{item.title}}
</div>
</div>
Upvotes: 0
Reputation: 27033
Store your items in an array
$scope.items = ['Wash', 'Tyres', 'Spares', 'Accessories'];
Then
<div ng-repeat="item in items">
Upvotes: 1