【发布时间】:2016-05-18 03:27:22
【问题描述】:
所以我想要完成的是:当用户点击 index.html 中的 a-tag 时,会导致他们进入状态“博客”,即 main。 html,我希望 main.html 中的 ui-view 元素自动显示 home.html。
我尝试在“博客”状态下使用abstract: true, template: '<ui-view>,然后为状态“blogs.home”提供一个空 url,以便它自动显示,但不幸的是,它只是让它填充 index.html 的 ui-view 元素。不是我想要的。
我正在尝试将 main.html 中的 ui-view 元素定位为默认填充 home.html。
任何帮助将不胜感激,我可以澄清在我的解释中不一定有意义的任何事情。提前致谢。
这是我的布局:
index.html
<body ng-controller="MainController">
<!-- HEADER -->
<div class="header">
<div class="title">
<i style="color: white;" class="fa fa-magic fa-2x"></i>
<h3>
<span>AngularJS Blog</span>
</h3>
</div>
<div class="nav-bar">
<div class="nav-div nav-div-one">
<a ui-sref="blogs"><i class="fa fa-archive fa-2x"></i></a>
</div>
<div class="nav-div nav-div-two">
<a ui-sref="newblog"><i class="fa fa-pencil fa-2x"></i></a>
</div>
</div>
</div>
<!-- VIEWS -->
<div ui-view class="main-fade"><div>
main.html
<div class="wrapper">
<div class="blog-container" ng-repeat="post in blog" ng-click="readPost(post._id)" ui-sref=".readblog">
<p><i class="fa fa-book"></i> {{ post.title }}</p>
<p>by {{ post.author }}</p>
<p>{{ post.pubdate | date }}</p>
<br>
<div>
<p>{{ post.body }}</p>
</div>
<br><br>
<div style="position: absolute; bottom: 10px; right: 10px;">
<button id="deletePost" ng-click="deletePost(post._id)">Delete Blog</button>
<button id="readPost" ng-click="readPost(post._id)" ui-sref=".readblog">Read Blog</button>
</div>
</div>
</div>
<div ui-view></div>
home.html
<div class="home">
<h1>The place to write stuff down.</h1>
</div>
app.js
var app = angular.module('blog-app', ['ui.router', 'ngAnimate']);
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/blogs/home');
$stateProvider
.state('blogs', {
url: '/blogs',
templateUrl: 'views/main.html',
controller: 'MainController'
})
.state('blogs.home', {
url: "",
templateUrl: "views/home.html",
MainController: "MainController"
})
.state('blogs.readblog', {
url: "/readblog",
templateUrl: "views/readblog.html",
controller: "MainController"
})
.state('newblog', {
url: '/newblog',
templateUrl: "views/newblog.html",
controller: "MainController"
});
}); //End Config. OK
【问题讨论】:
标签: javascript html angularjs angular-ui-router