angularjs - AngularJS ng-repeat 带有过滤器 - notarray 错误,预期的数组但收到:
问题描述
templates.js 这是控制器文件
.controller('TemplatesDetailsCtrl', ['$scope', '$routeParams', '$http', '$filter', function($scope, $routeParams, $http, $filter){
var templateId = $routeParams.templateId;
$http.get('json/templates.json')
.then(function(response){
$scope.templates = $filter('filter')(response , function(d){
return d.id == templateId
})[0];
$scope.mainImage = $scope.template.images[0].name;
});
}]);
模板详细信息.html
<img class="img-full" src="img/{{mainImage}}">
解决方案
正如错误所说,过滤器需要将数组作为输入,但是您正在传递一个对象,请尝试response.data
$scope.templates = $filter('filter')(response.data , function(d){
return d.id == templateId
})[0];
推荐阅读
- python - How to sort pandas dataframe by two date columns
- python - 带孔的矩形阵列
- firebase - Flutter Firebase Analytics: Track page changes with onGenerateRoute
- php - 链接到 Mysql 和搜索功能的下拉框
- r - R中接受和返回向量的函数
- python - 有时为什么我们必须在 python 中将参数作为元组传递?
- reactjs - 使用值从 React 调用 .NET Core 控制器方法
- java - @DataJpaTest 使用存储库保存实体,无法使用 JdbcTemplate 检索数据
- javascript - 如何正确设置元素的高度属性?
- python - 将数据集拆分为训练和测试以在 python 中进行时间序列分析