简体   繁体   中英

$state.go doesn't work with ng-click

When an item is clicked, its path is sent as parameter to state function and the state function does $state.go to load a state with the passed path as parameter.

This doesn't seem to work. What am I missing here?

Template

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

Controller

 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 }); } }) } ]) 

Router

 .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" } } }); 

handler.get("/home").then(function(response) { looks like a promise to me. Try moving $scope.state definition outside this promise.

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
      });
    }
  }
])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM