![](/img/trans.png)
[英]AngularJS + Fullcalendar send error TypeError: Cannot read property '__id' of undefined
[英]AngularJS error : TypeError: Cannot read property 'images' of undefined
AngularJS:v1.5.11
我试图显示来自JSON数组的图像。
这是正确的方法$scope.mainImage = $scope.template.images[0].name;
: $scope.mainImage = $scope.template.images[0].name;
。 这是错误中的行,它表示无法读取images
属性。
我的控制器在templates.js文件中:
.controller("TemplatesDetailsCtrl", ["$scope", "$routeParams", "$http", "$filter", function($scope, $routeParams, $http, $filter ){
var templateId = $routeParams.templateID;
$http.get("json/templates.json").success(function(data){
$scope.template = $filter("filter")(data, function(d){
return d.id == templateId;
})[0];
$scope.mainImage = $scope.template.images[0].name; //THIS IS LINE 30
});
}]);
我正在尝试显示数组中的第一张图像。 所以我的HTML是:
<img class="img-full" src="img/{{mainImage}}">
请帮忙。
似乎未定义“模板”对象。 您可以在尝试使用undefined
的属性之前对其进行测试:
if ($scope.template)
$scope.mainImage = $scope.template.images[0].name; //THIS IS LINE 30
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.