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
是一个列表
您想要实现的是获取列表列表
渲染它的简单方法是使用2ng 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
是一个列表
您想要实现的是获取列表列表
渲染它的简单方法是使用2ng 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}