0

Here is my code below:

 vm.getid = function(){
        $http({
            method: 'GET',
            url: 'api.json',
        })
            .then(function successCallback(data) {
                $scope.id = data.data;
                console.log($scope.id);
                $scope.split = $scope.id.split('/');
            }, function errorCallback(response) {
                console.log(response);
                console.log('error');
            });

    };

And here is my html, but it does not work :

<div ng-repeat="s in split">
  {{s}}
</div>

Plunker : http://plnkr.co/edit/g1t4pludTTIAJYKTToCK?p=preview

I want to use ng-repeat $scope.split Thanks!

2 Answers 2

2

$scope.id is a list.

What you want to achieve is to get list of lists

The easy way to render it, to use 2 ng-repeats

What about:

<div ng-repeat="i in id">
    <div ng-repeat="s in i.split('/')">
    {{s}}
  </div>
</div>

Demo 1


Or create split list as:

$scope.split = [];
angular.forEach($scope.id, function (item) {
    $scope.split.push(item.split('/'));
});

so HTML will look like:

<div ng-repeat="sp in split">
    <div ng-repeat="s in sp">
    sub: {{s}}
  </div>
</div>

Demo 2

Sign up to request clarification or add additional context in comments.

Comments

0

printing out id you can see it is an array, not a string

["/big_big_package","/door/cooler","/door/chair","/door","/lets/go/deeper/than/this","/lets/go/deeper","/low"]

and trying to split it gives the following error in console

$scope.id.split is not a function

you can't split an array, you probably want to split each element in the array

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.