嗨我不斷收到此錯誤。我試圖讓破碎的圖像圖標不出現在Angular Ionic應用程序中。我有這個功能,但它一直說anonImg沒有定義。我不知道如何定義這個?函數未定義在角
function anonImg(image){
image.src = 'https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg';
}
和我的HTML是
<ion-content class="climb-pics">
<img ng-src="{{urlForImage(selected_.images)}}"/>
<img onerror="anonImg(this);" ng-src="{{urlForImage(selected_.imageTwo)}}"/>
<button type="button" class="button button-assertive" ng-click="closeModal(1)">Close</button>
<p> </p>
</ion-content>
我應該在一個函數或東西被包裝的功能?我只是不現在什麼時候我得到的錯誤做「的ReferenceError:anonImg沒有定義」
這裏是我的控制器代碼:
.controller('ClimbController', ['$scope', '$stateParams', 'Products', 'Climbs', '$ionicModal', '$localStorage', '$cordovaCamera', '$cordovaFile',
function($scope, $stateParams, Products, Climbs, $ionicModal, $localStorage, $cordovaCamera, $cordovaFile) {
$scope.product_id = $stateParams.productId;
console.log('ClimbController: ' + $scope.product_id);
// ClimbsController: 2
$scope.urlForImage = function(imagePath) {
console.log('imagePath: ' + imagePath);
return Products.urlForImage($scope.product_id, imagePath);
}
var filename = Products.getFilenameFromLocalStorage($scope.product_id);
console.log(filename);
var climbId = $stateParams.climbId;
var areaId = $stateParams.areaId;
if (!isNaN(climbId)) {
climbId = parseInt(climbId);
}
if (!isNaN(areaId)) {
areaId = parseInt(areaId);
}
$scope.selected_ = {};
$scope.items = [];
$scope.details = true;
$scope.data = '';
$scope.noteParams = {
text: null
};
// looping though all data and get particular product
$scope.selectClimb = function(areas){
areas.forEach(function(data) {
if(data._id == climbId){
$scope.selected_ = data;
}
});
}
// get all posts // try some function to get a single produt from server
$scope.getPosts = function(){
Products.loadGuidebook(filename).then(function(data) {
// NOTE: data = the whole feed.json file
console.log(data);
// data = feed.json file
var climbs = [];
data.areas.map(function(area) {
if (area._id === areaId) {
climbs = area.climbs;
}
});
$scope.selectClimb(climbs);
},
function (error) {
console.log(error);
});
}
// picture slider logic
$scope.allImages = $scope.images;
//hide div with broken images
anonImg = function(image){
image.src = 'https://instagramimages-a.akamaihd.net/profiles/anonymousUser.jpg';
}
$scope.load();
$scope.getPosts();
}
])
課程後的控制器代碼 – Sajeetharan
,您不能使用功能的HTML,如果你沒有這個功能分配給範圍,所以你應該設置scope.nonImage = function(){blablalbla;} –