javascript - 同一 View 中的 UI-Router 路由(查看和编辑)

标签 javascript angularjs angular-ui-router

我无法在 UI-Router 中将状态从查看页面更改为编辑页面,反之亦然。 我尝试过的事情:

Controller :

$stateProvider
        .state('showViewA', {
            views: {
                " ": {
                    template: "default.html",
                    controller:"DefaultController.ts"
                     },
                "viewB@showViewA": {
                    template: "viewPage.html",
                    controller:"DefaultController.ts"
                    }
            } 
        }) 
    .state('showViewA@EditshowViewA', {
            views: {
                " ": {
                    template: "defaultEdit.html",
                    controller:"DefaultEditController.ts"
                     }                 
            } 
        }) 
    .state('showViewA@ViewshowViewA', {
            views: {
                " ": {
                    template: "defaultShow.html",
                    controller:"DefaultShowController.ts"
                     }                 
            } 
        }) 

default.html中,我仅加载第一次打开页面时需要看到的 View ,即编辑页面

<div ui-view="showViewA"></div> 

显示编辑页面。保存编辑页面时,我需要将编辑页面替换为我已指定状态 showViewA@ViewshowViewA 的 View 页面。但它不是重定向。我能知道我哪里错了吗?

最佳答案

a working plunker

假设这是 default.html 内容:

<div >
  <h2>The default view (layout)</h2>

  <b>place holder for viewB</b>
  <hr />

  <div ui-view="viewB"></div>      
</div>

然后让我们的状态使用这些链接:

 <a ui-sref="showViewA">
 <a ui-sref="showViewA.EditshowViewA">
 <a ui-sref="showViewA.ViewshowViewA">

这将是调整后的状态定义(更改为新行 - 旧行保留注释值)

具有内部 View 的父状态,注入(inject)ui-view="viewB"占位符/ anchor

    .state('showViewA', {
      url: '/',
      views: {
        //" ": {
        "": {
          //template: "default.html",
          templateUrl: "default.html",
          //controller:"DefaultController.ts"
          controller: "DefaultController"
        },
        "viewB@showViewA": {
          //template: "viewPage.html",
          templateUrl: "viewPage.html",
          //controller: "DefaultController.ts"
          controller: "DefaultController"
        }
      }
    })

子级将其 View 注入(inject)同一个 ui-view="viewB"

  //.state('showViewA@EditshowViewA', {
  .state('showViewA.EditshowViewA', {
    views: {
      //" ": {
      "viewB": {
        //template: "defaultEdit.html",
        templateUrl: "defaultEdit.html",
        //controller:"DefaultEditController.ts"
        controller: "DefaultEditController"
      }
    }
  })
  //.state('showViewA@ViewshowViewA', {
  .state('showViewA.ViewshowViewA', {
    views: {
      //" ": {
      "viewB": {
        //template: "defaultShow.html",
        templateUrl: "defaultShow.html",
        //controller:"DefaultShowController.ts"
        controller: "DefaultShowController"
      }
    } 
  })

检查一下here

关于javascript - 同一 View 中的 UI-Router 路由(查看和编辑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30443770/

相关文章:

Javascript 在具有特定 id 的行后将行插入表中

javascript - Angular Bootstrap ui 使轮播垂直滑动

javascript - 如何通过工厂请求传递参数

javascript - angular-ui-router 的嵌套状态 URL 不正确

javascript - 退出 ui-router 中的粘滞状态

javascript - 如何获取键盘上的箭头键以触发博客中的导航(上一页/下一页)链接

javascript - 设置函数默认this值

javascript - 需要将 var 设置为链接

angularjs - 使用 $http-backend 测试 Angular 时为单个请求定义多个响应

angularjs - 在状态更改 + 后退按钮上使用 angular ui-router 向左/向右滑动(用于移动设备)