javascript - Angular UI 路由器抽象模板

标签 javascript angularjs html

我有一个工作应用程序,所有内容都与如下结构一起工作:

<div class="container">
  <div class="row">
    <div class="col-md-2">
      <!-- alot of repeated html used by all the states here -->
    </div>
    <div class="col-md-8">
      <!-- the unique html specific to the state goes here -->
    </div>
  </div>
</div>

路由器配置如下

$stateProvider
  .state('dashboard', {
    url: '/dashboard',
    templateUrl: './partials/dashboard.html'
  })
  .state('applications', {
    url: '/applications',
    templateUrl: './partials/applications.html'
  })
  .state('server', {
    url: '/server',
    templateUrl: './partials/server.html'
  })

问题是这里有很多重复的html代码。 如何制作一个所有状态都继承的接口(interface),以便我专注于状态的唯一 html。

最佳答案

您可以使用抽象状态,例如称为:

.state('base', {
  url: '',
  templateUrl: 'path/to/layout.html', // here you should declare named ui-views, f.e. named content
  abstract: true
})
.state('base.dashboard', {
  url: '/dashboard',
  views: {
    content: {
      templateUrl: "/path/to/dashboard/content.html"
    }
  }
})
// the rest of the states goes the same below.
... 

希望能有所帮助。

更多信息请参阅here .

关于javascript - Angular UI 路由器抽象模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308529/

相关文章:

javascript - JavaScript ES promise 履行处理程序作业队列是否在所有 setTimeout 和 setInterval 处理程序队列之前执行?

javascript - 如何将对象或变量值从html脚本标记传递到 Angular Controller

javascript - 使用 jQuery,如何删除动态添加到页面头部的类

javascript - 向函数发送参数

javascript - 尝试将 .match 结果推送到数组中

javascript - 如何使用下划线返回对象作为 groupby 函数中的键

javascript - 使用 if else 显示和隐藏标签

javascript - 德拉古拉掉落到同一类别的不同目标

javascript - 为 d3 网络图添加选择框

javascript - Angularjs 与 browsersync post 方法作为选项发送