简体   繁体   English

$ state.go不适用于ng-click

[英]$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. 单击某项时,其路径将作为参数发送到state函数,状态函数执行$state.go以使用传递的路径作为参数加载状态。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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