[英]Is there a cleaner way to use angular ui nested routes with ui-router?
[英]ui-router nested routes not working
大家好,我正在嘗試使用角度ui路由器在我的網站中進行嵌套路由,但我不知道我要去哪里
這是我的代碼
app.js
var faqApp = angular.module('faqApp', ['ui.router']);
faqApp.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home',{
url: '/home',
templateUrl: 'templates/home.html',
controller: 'homeCtrl'
})
.state('home.contactform', {
templateUrl: 'templates/contactform.html',
})
});
home.html
<div class="faq_head clearfix">
<a href="https://crownit.in"><img src="images/backbtn.png"></a>
<h1>Help</h1>
</div>
<div ui-view></div>
<div class="faq_inner">
<h2 class="faq_heading">FAQs</h2>
<ul>
<li ng-repeat="option in faqoptions">
<a href="{{option.url}}" class="clearfix">
<span class="icon">
<img ng-src="{{option.image}}">
</span>
<span class="faq_name">{{option.name}}</span>
<span class="arrow">
<img src="images/right_arrow.png">
</span>
</a>
</li>
</ul>
</div>
<div class="bottom_btn_box">
<a href="http://website_wordpress-dev.crownit.in/termsAndroid" class="bottom_btn">Terms & Conditions</a>
<a href="http://website_wordpress-dev.crownit.in/creditsAndroid" class="bottom_btn">Credits</a>
</div>
index.html
<!doctype html>
<html>
<head>
<title>Frequently ask questions</title>
<link rel="stylesheet" type="text/css" href="css/libs/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div ng-app="faqApp">
<div ui-view></div>
</div>
<script src="js/libs/jquery-1.12.3.min.js"></script>
<script src="js/libs/angular.js"></script>
<script src="js/libs/angular-ui-router.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controller/homeCtrl.js"></script>
</body>
</html>
在上面的代碼中,我通過ui-view
在index.html
調用了“ home.html”,然后在home.html
調用了contactform.html
,但沒有加載contactform.html
。
您還需要定義網址,
.state('home.contactform', {
url: "/contactform",
templateUrl: 'templates/contactform.html',
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.