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;
});
}]);
template-details.html
<img class="img-full" src="img/{{mainImage}}">
答案 0 :(得分:1)
如错误所示,过滤器需要获取数组作为输入,但是要传递对象,请尝试 response.data
$scope.templates = $filter('filter')(response.data , function(d){
return d.id == templateId
})[0];