2015-07-06 2 views
1

Когда элемент щелкнут, его путь отправляется как параметр в функцию state, а функция состояния выполняет $state.go для загрузки состояния с переданным путем в качестве параметра.

Это не работает. Что мне здесь не хватает?

Шаблон

<div ng-click="state(item.class, item.path, item.mime_type)">

Контроллер

controller("groupsListCtrl", ["$scope", "handler", "$state", 
 
    function($scope, handler, $state) { 
 
    handler.get("/home").then(function(response) { 
 
     $scope.data = response; 
 
     $scope.items = $scope.data.inventory; 
 

 
     $scope.state = function(stateType, objectPath, mimeType) { 
 
     $state.go("workarea.user", { 
 
      path: objectPath 
 
     }); 
 
     } 
 
    }) 
 
    } 
 
])

Маршрутизатор

.state("workarea.user", { 
 
    url: "^/workarea/:path", 
 
    requireLogin: true, 
 
    views: { 
 
    "options": { 
 
     templateUrl: "/views/options.html", 
 
     controller: "optionsCtrl" 
 
    }, 
 
    "workspace": { 
 
     templateUrl: "/views/workspace.html", 
 
     controller: "workspaceCtrl" 
 
    }, 
 
    "comments": { 
 
     templateUrl: "/views/comments.html", 
 
     controller: "commentsCtrl" 
 
    } 
 
    } 
 
});

ответ

0

handler.get("/home").then(function(response) { выглядит как обещание мне. Попробуйте переместить $scope.state определение вне этого обещания.

controller("groupsListCtrl", ["$scope", "handler", "$state", 
    function($scope, handler, $state) { 
    handler.get("/home").then(function(response) { 
     $scope.data = response; 
     $scope.items = $scope.data.inventory; 
    }); 

    $scope.state = function(stateType, objectPath, mimeType) { 
     $state.go("workarea.user", { 
     path: objectPath 
     }); 
    } 
    } 
]) 
+0

Это обещание. Но это решение, похоже, не работает. – Jaipradeesh

+0

Вы переместили '$ scope.state' за рамки обещания? –

+0

Да. функция переносится из обещания. Впрочем, не повезло. – Jaipradeesh

Смежные вопросы