0
我有這樣的功能:
// Gets our sport
get: function (slug, kit) {
// If we have no slug, exit the function
if (!slug)
return $q.reject('No slug supplied.');
// Try to get our sport
return moltin.categories.get(slug).then(function (response) {
// If we have a kit
if (kit) {
// Assign our sport to our kit
kit.team.sport = response.slug;
}
// Return our response
return response;
});
}
正如你可以看到我使用$ q.reject()如果我需要的參數沒有設置。 的問題是,在一個$狀態解決方法,如果我調用這樣的功能:
resolve: {
sport: ['$stateParams', 'kit', 'SimpleDesignerSharedSportService', function ($stateParmas, kit, sharedSport) {
// Get our slug
var slug = $stateParmas.sport || kit.team.sport;
// Get our sport
return sharedSport.get(slug, kit);
}]
}
我認爲將不會被顯示(這只是空白)。但是,如果我我的決心改成這樣:
resolve: {
sport: ['$stateParams', 'kit', 'SimpleDesignerSharedSportService', function ($stateParmas, kit, sharedSport) {
// Get our slug
var slug = $stateParmas.sport || kit.team.sport;
// Get our sport
return sharedSport.get(slug, kit).then(function (response) {
return response;
}, function (error) {
return null;
});
}],
pageTitle: ['PageHead', function (service) {
service.setTitle('Kudos Sports - Create your kit');
}]
}
它的工作原理。我不想指定一個成功和失敗的方法。無論如何,我可以解決它嗎?