我主要担心的是这个控制器的结束。在$ scope.navigate函数中。基本上我想通过搜索arg.item_type ==“DEAL”或arg.item_type ==“EVENT”等来查看“商品”的类型。我的问题与$ location.path有关。我不知道如何在Angular中使用$ location.path重定向。因某些原因不起作用。
在控制台中,它说“$ location未在Scope。$ scope.navigate中定义”
任何人都有任何想法如何运作?感谢
// BUDGET PROFILE
// A simple controller that fetches a list of data from a service
.controller('BudgetIndexCtrl', function($scope, $stateParams, $ionicLoading, BudgetService) {
console.log($stateParams);
var loading = $ionicLoading.show({
content: 'Loading...',
showBackdrop: true,
maxWidth: 200,
showDelay: 500
});
$scope.offers = BudgetService.get($stateParams);
console.log($scope.offers);
loading.hide();
// this function is done to look for the TYPE of 'offer'
$scope.navigate = function(arg) {
if (arg.item_type == "DEAL") {
$location.path("/tab/deals/" + arg.id);
$scope.$apply();
}
if (arg.item_type == "EVENT") {
$location.path("/tab/events/" + arg.id);
$scope.$apply();
}
if (arg.item_type == "ATTRACTION") {
$location.path("/tab/attractions/" + arg.id);
$scope.$apply();
}
//console.log(arg);
};
})