Ionic UI路由器不工作
Ionic UI Router Not Working
我已经创建了这个简单的Ionic应用程序。只是尝试学习UI路由器是如何工作的。
然而,当我运行它时,什么也没有出现。此外,在Google Chrome的开发人员工具中也没有显示任何内容。
index . html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user- scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<!--
The views will be rendered in the <ion-nav-view> directive below
Templates are in the /templates folder (but you could also
have templates inline in this html file if you'd like).
-->
<ion-nav-view></ion-nav-view>
</body>
</html>
app.js
var app = angular.module('starter', ['ionic']);
app.config(function($stateProvider) {
$stateProvider
.state('index', {
url: '/',
templateUrl: 'templates/home.html'
})
.state('music', {
url: '/music',
templateUrl: 'templates/music.html'
});
});
模板/home。
<script id="home" type="text/ng-template">
<!-- The title of the ion-view will be shown on the navbar-->
<ion-view view-title="Home">
<ion-content ng-controller="HomeCtrl">
<!-- The the content of the page -->
<a href="#/music">Go to music page!</a>
</ion-content>
</ion-view>
</script>
模板/music.html
<script id="home" type="text/ng-template">
<!-- The title of the ion-view will be shown on the navbar-->
<ion-view view-title="Home">
<ion-content ng-controller="HomeCtrl">
<!-- The the content of the page -->
<a href="#/music">Go to music page!</a>
</ion-content>
</ion-view>
</script>
编辑:在查看您的github repo后,您的app.js没有调用run()。
这是一些工作,在app.js定义你的控制器和状态。如你所见,我将我的视图命名为main。
app.controller('HomeCtrl', function ($scope) {
})
app.controller('MusicCtrl', function ($scope) {
})
app.config(function($stateProvider) {
$stateProvider
.state('index', {
url: '/',
views: {
'main': {
templateUrl: 'templates/home.html',
controller: 'HomeCtrl'
}
}
})
.state('music', {
url: '/music',
views: {
'main': {
templateUrl: 'templates/music.html',
controller: 'MusicCtrl'
}
}
});
});
在index.html中,我将视图命名为:
<ion-nav-view name="main"></ion-nav-view>
hom.html
<!-- The title of the ion-view will be shown on the navbar-->
<ion-view view-title="Home">
<ion-content>
<!-- The the content of the page -->
<a href="#/music">Go to music page!</a>
</ion-content>
</ion-view>
music.html类似。
请注意,对于一个真正的项目,我不会在app.js中定义控制器和状态,我会在每个页面有3个文件:状态,控制器和模板在一个专用文件夹内。
如果home.html和music.html确实在不同的文件中,那么您不需要将它们包装在<script>
标记中。从这里开始。
相关文章:
- AngularJS UI路由器不能像ng路由器那样工作
- 流星铁路由器动态段不工作
- 当名称空间在id参数之前声明时,Angular UI路由器停止工作
- angular ui路由器不工作
- 无法获取用户 ID 路由参数以在反应路由器中继上工作
- ExpressJS路由器不工作
- 铁:路由器工作很奇怪 - 将我发送到模板然后返回
- Angular (1.5.0) ng 路由器不工作
- ng-controller工作,UI路由器:控制器不是
- UI 路由器不加载 rawgit 中的视图,但在本地工作
- 如何在Microsoft IIS上使用反应路由器(createBrowserHistory)使路由工作
- React路由器不工作
- angular ui路由器状态模板不工作
- 使用react路由器,redux将无法工作
- 具有url参数的角度状态/路由器不工作
- 为什么angularjs路由器在这里不工作
- Angular UI路由器工作不正常
- 骨干路由器是'工作不正常
- 无法让UI路由器在我的Angular Framework中工作
- 我的主干js路由器是't工作