角UI路由器 - 如何访问嵌套,命名视图参数,父模板通过呢? [英] Angular ui-router - how to access parameters in nested, named view, passed from the parent template?

查看:117
本文介绍了角UI路由器 - 如何访问嵌套,命名视图参数,父模板通过呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试图同时使用的用户界面 - 路由器,运行到困难控制器ViewWorklogCrtl访问的参数。

Hi I am trying to access a parameter in the controller "ViewWorklogCrtl" while using ui-router and running into difficulty.

基本上,我的父母模板包含:

Basically, my parent template contains:

a(ui-sref="instance-ticket.worklog({id:{{ticket.testnum}}})") show

再进一步​​下跌的页面:

and then further down the page:

section(ui-view="top-section")

然后在我的app.js,包含客户端的路由信息​​总之我有:

Then in my app.js, containing client-side routing info in short I have:

 $stateProvider
.state('instance-ticket', {
  url: '/ticket/:instanceID',
  templateUrl: 'partials/instance-ticket',
  controller: 'ViewTicketCrtl'
})
.state('instance-ticket.worklog', {
  views:{
    'top-section':{
      templateUrl:'/partials/ticket.worklog.jade',
      controller: 'ViewWorklogCrtl'
      }
  }
  })

模板加载工作正常,问题,问题,我无法找到一个答案是 - 如何访问testnum通过ui-SREF环节传递,并在ViewWorkLogCtrl内......有没有更好的方法来呢?

The template loading is working correctly, the issue and question I can't find an answer to is - how to access "testnum" being passed through the ui-sref link, to and within the ViewWorkLogCtrl... Is there a better approach to this?

大部分谢谢!

推荐答案

实例ID 被声明为参数,所以我们可以这样访问

The instanceID is declared as an parameter, so we can access it like this

.controller('ViewWorklogCrtl',
    [       '$scope','$stateParams'
    function($scope , $stateParams ) {    
        // 
        $scope.instanceID = $stateParams.instanceID;
        ...

所有其他细节可以在这里<一个发现href=\"https://github.com/angular-ui/ui-router/wiki/URL-Routing\">https://github.com/angular-ui/ui-router/wiki/URL-Routing

All the other details could be found here https://github.com/angular-ui/ui-router/wiki/URL-Routing

和调用 UI-SREF 应该是这样的。

<a ui-sref="instance-ticket.worklog({ instanceID:ticket.testnum })" >..

扩展

在我们想从目前的从父2)testnum得到两个参数:1)实例ID的情况下,我们必须调整状态确定指标这样

In case that we would like to get two parameters, 1) instanceID from the parent 2) testnum from the current, we have to adjust the state defintion like this

.state('instance-ticket', {
  url: '/ticket/:instanceID',      // instanceID
  templateUrl: 'partials/instance-ticket',
  controller: 'ViewTicketCrtl'
})
.state('instance-ticket.worklog', {
  // new param defintion
  url: '/worklog/:testnum',         // testnum
  views:{
    'top-section':{
      templateUrl:'/partials/ticket.worklog.jade',
      controller: 'ViewWorklogCrtl'
      }
  }

以及 UI-SREF

<a ui-sref="instance-ticket.worklog({ instanceID:1, ticket.testnum:2 })" >..

我们可以访问它是这样的:

And we can access it like this:

.controller('ViewWorklogCrtl',
    [       '$scope','$stateParams'
    function($scope , $stateParams ) {    
        // 
        console.log($stateParams.instanceID)
        console.log($stateParams.testnum)
        ...

这篇关于角UI路由器 - 如何访问嵌套,命名视图参数,父模板通过呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆