$ state.go不适用于ng-click

时间:2015-07-06 10:24:55

标签: javascript angularjs

单击某个项目时,其路径作为参数发送到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"
    }
  }
});

1 个答案:

答案 0 :(得分: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
      });
    }
  }
])