我是第一次使用 AngularJS。我已经在包含 header.html 模板的 index.html 页面中成功实现了一个 ng-view。所以它看起来像下面
但现在我正在创建一个仪表板 (dashboard.html)。所以,除了 header.html 之外,我还有一个左侧菜单,所以它看起来像这样:
我的 index.html 是这样的:
<div ng-include="'templates/header.html'"></div>
<div class="main" id="main-no-space" >
<div id="main-page">
<div id="wrapper" class="container">
<div class='container'>
<div ng-view></div>
</div>
</div>
</div>
<div ng-include="'templates/footer.html'">
我的 dashboard.html 是这样的:
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<a ng-href="#/link1">Link 1</a>
</li>
<li>
<a ng-href="#/link2">Link 2</a>
</li>
<li>
<a ng-href="#/link3">Link 3</a>
</li>
</ul>
</div>
最佳答案
试试这个:
angular.module('app', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/dashboard', {
templateUrl: 'dashboard.html',
controller: DashboardCtrl
})
.otherwise({
redirectTo: '/dashboard'
});
}]);
function DashboardCtrl() {
}* {
box-sizing: border-box;
}
#main:after {
content: "";
display: block;
clear: both;
}
#header {
padding: 20px;
border: 1px solid #000;
}
#main {
padding: 20px;
border: 1px solid #000;
}
#sidebar {
padding: 20px;
border: 1px solid #000;
float: left;
width: 20%;
}
#content {
padding: 20px;
border: 1px solid #000;
float: right;
width: 78%;
}
#footer {
padding: 20px;
border: 1px solid #000;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular-route.js"></script>
<div ng-app="app">
<div ng-include="'header.html'" id="header"></div>
<div class="main" id="main-no-space">
<div id="main-page">
<div id="wrapper" class="container">
<div class="container">
<div ng-view id="main">loading...</div>
</div>
</div>
</div>
<div ng-include="'footer.html'" id="footer"></div>
</div>
<script type="text/ng-template" id="dashboard.html">
<div ng-include="'sidebar.html'" id="sidebar"></div>
<div id="content">dashboard</div>
</script>
<script type="text/ng-template" id="header.html">
header
</script>
<script type="text/ng-template" id="sidebar.html">
sidebar
</script>
<script type="text/ng-template" id="footer.html">
footer
</script>
</div>
JSFiddle http://jsfiddle.net/mcVfK/928/
关于javascript - 如何用 Angular 做多个 View 来支持页眉和侧边栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29114800/
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi
除了可访问性标准不鼓励使用这一事实指向当前页面的链接,我应该怎么做重构以下View代码?#navigation%ul.tabbed-ifcurrent_page?(new_profile_path)%li{:class=>"current_page_item"}=link_tot("new_profile"),new_profile_path-else%li=link_tot("new_profile"),new_profile_path-ifcurrent_page?(profiles_path)%li{:class=>"current_page_item"}=link_tot("p
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
我正在尝试以一种更类似于普通RubyGem结构的方式构建我的Sinatra应用程序。我有以下文件树:.├──app.rb├──config.ru├──Gemfile├──Gemfile.lock├──helpers│ ├──dbconfig.rb│ ├──functions.rb│ └──init.rb├──hidden│ └──Rakefile├──lib│ ├──admin.rb│ ├──api.rb│ ├──indexer.rb│ ├──init.rb│ └──magnet.rb├──models│ ├──init.rb│ ├──invite.rb│ ├─
A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(
我有一个非常简单的Controller来管理我的Rails应用程序中的静态页面:classPagesController我怎样才能让View模板返回它自己的名字,这样我就可以做这样的事情:#pricing.html.erb#-->"Pricing"感谢您的帮助。 最佳答案 4.3RoutingParametersTheparamshashwillalwayscontainthe:controllerand:actionkeys,butyoushouldusethemethodscontroller_nameandaction_nam