Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 成角分裂_Angularjs_Split - Fatal编程技术网

Angularjs 成角分裂

Angularjs 成角分裂,angularjs,split,Angularjs,Split,下面是我的代码: vm.getid = function(){ $http({ method: 'GET', url: 'api.json', }) .then(function successCallback(data) { $scope.id = data.data; console.log($scope.id);

下面是我的代码:

 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');
            });

    };
这是我的html,但它不起作用:

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

{{s}
普朗克:

我想使用ng repeat
$scope.split

谢谢

打印出id您可以看到它是一个数组,而不是字符串

["/big_big_package","/door/cooler","/door/chair","/door","/lets/go/deeper/than/this","/lets/go/deeper","/low"]
尝试拆分它会在控制台中出现以下错误

$scope.id.split is not a function

您不能拆分数组,您可能需要拆分数组中的每个元素

打印出id您可以看到它是一个数组,而不是字符串

["/big_big_package","/door/cooler","/door/chair","/door","/lets/go/deeper/than/this","/lets/go/deeper","/low"]
尝试拆分它会在控制台中出现以下错误

$scope.id.split is not a function

您不能拆分数组,可能需要拆分数组中的每个元素。

$scope.id
是一个列表

您想要实现的是获取列表列表

渲染它的简单方法是使用2
ng repeat
s

那么:

<div ng-repeat="i in id">
    <div ng-repeat="s in i.split('/')">
    {{s}}
  </div>
</div>
所以HTML看起来像:

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

子:{{s}

$scope.id
是一个列表

您想要实现的是获取列表列表

渲染它的简单方法是使用2
ng repeat
s

那么:

<div ng-repeat="i in id">
    <div ng-repeat="s in i.split('/')">
    {{s}}
  </div>
</div>
所以HTML看起来像:

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

子:{{s}