javascript - AngularJS UI 路由器 : Rendering parent partial with child partial

标签 javascript angularjs url-routing

我正在使用UI-Router AngularJS 框架,用于渲染嵌套部分。我在渲染父部分及其子部分时遇到问题。这是我的代码:

window.app.config(['$stateProvider', '$urlRouterProvider', 
  function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
    .state('class', {
        url: '/classes/:classId',
        templateUrl: '/views/class.html',
        controller: 'ClassCtrl',
    })
      .state('class.questionList', {
        url: '',
        templateUrl: '/views/questionList.html',
      })
  }]);

在子状态的声明中,我将 url 设置为空字符串,以便它能够与其父状态同时呈现。但是,这不起作用,只有父 View 正在渲染。

最佳答案

给父状态添加属性“abstract: true”,通知UI-Router该状态只能通过子状态的激活来激活。这将使 URL/classes/:classId 激活这两种状态。

关于javascript - AngularJS UI 路由器 : Rendering parent partial with child partial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18976716/

相关文章:

javascript - 如何让屏保根据时间出现和消失?

javascript - 当使用 apply() 和 call() 方法很容易继承时,为什么人们在 JavaScript 中使用原型(prototype)?

javascript - 推送覆盖以前的 ui-grid 行数据

javascript - Kendo UI 与 AngularJs : How to bind data on textbox fields when user select row in a grid

javascript - 可以使用这个 angularJS html 属性 : ng-include ="{{...}}"?

java - 本地化路由和 URL 字符串

javascript - Node.js - 如何初始化/定义 req.body?

javascript - django rest framework API编辑功能

javascript - 使用 AJAX 和 PHP 删除用户记录时面临的问题

CakePHP 登录重定向到请求的 URL