我正在处理一个图库页面模板,该模板接收一个对象并使用ng-show或ng-hide显示某些信息(如果该对象包含它)。我使用的每个ng-show或ng-hide实例都会创建一个" TypeError:f不是一个函数"错误。
我正在使用工厂加载包含所有绘制对象数组的json文件。然后我使用$ filter来找到我将用于单个绘图页面的特定对象。然后我使用$ scope变量将对象公开给模板。
我正在使用的示例对象:
{
"category" : "Flowers",
"filename" : "swami",
"location" : "",
"medium" : "canvas",
"notes" : "",
"paint" : "oil",
"price" : 400,
"size" : "16x20",
"title" : "Swami (Day Lily)"
}
以下是模板的一部分:
<div class="container">
<div class="gallery-tile">
<div class="row">
<div class="col-sm-6 painting-col">
<h1>{{painting.title}}</h1>
<p><em>{{painting.paint}} on a {{painting.size}} inch {{painting.medium}}</em></p>
<p ng-show="location"><strong>Location:</strong> {{painting.location}}</p>
<p ng-show="notes"><strong>Notes:</strong> {{painting.notes}}</p>
<hr>
<p ng-show="painting.price"><strong>Price:</strong> {{painting.price | currency}}</p>
<p ng-hide="painting.price"><em>This painting is not available for sale.</em></p>
<br>
<a href="#/contact" ng-show="painting.price" class="order-link hvr-icon-forward">Order Policy</a>
<hr>
</div>
<div class="col-sm-6">
<a href="images/max/{{painting.filename}}.jpg" data-featherlight="image">
<img ng-src="images/full/{{painting.filename}}.jpg" class="painting-detail" />
</a>
<p class="text-muted">Click on the painting for a larger view.</p>
</div>
</div>
</div>
</div>
页面控制器:
cpControllers.controller('PaintingDetail', ['$scope', '$routeParams', '$http',
'$filter', 'Painting',
function($scope, $routeParams, $http, $filter, Painting) {
Painting.get().$promise.then(function(response) {
$scope.painting = $filter('filter')(response.paintings, {filename: $routeParams.painting})[0];
if ($scope.painting.notes != "") {
$scope.notes = true
} else {
$scope.notes = false
}
if ($scope.painting.location != "") {
$scope.location = true
} else {
$scope.location = false
}
});
}]);
工厂:
cpServices.factory('Painting', ['$resource',
function($resource) {
return $resource('paintings/paintings.json', {}, {
query: {method: 'GET'},
});
}]);
最后,在浏览器控制台中看到错误(图像的声誉不够......):
11 angular.js:11655 TypeError: f is not a function
at angular.js:16299
at e (angular.js:4924)
at angular.js:5312
提前感谢任何建议。