Angularjs 离子路由和模板不工作
我也不熟悉离子和角度用户界面。我正在尝试使用模板加载我的Ionic应用程序中的第一页。我的文件夹结构如下 我想使用我的Angularjs 离子路由和模板不工作,angularjs,angular-ui-router,ionic-framework,Angularjs,Angular Ui Router,Ionic Framework,我也不熟悉离子和角度用户界面。我正在尝试使用模板加载我的Ionic应用程序中的第一页。我的文件夹结构如下 我想使用我的index.html作为所有模板的容器。我正试图使用list.html作为模板,在我的应用程序首次加载时将其加载到index.html。我已经尝试了下面的代码,我被卡住了 .config(function($urlRouterProvider, $stateProvider){ $stateProvider .state('index', { url:
index.html
作为所有模板的容器。我正试图使用list.html
作为模板,在我的应用程序首次加载时将其加载到index.html
。我已经尝试了下面的代码,我被卡住了
.config(function($urlRouterProvider, $stateProvider){
$stateProvider
.state('index', {
url: '/',
abstract: true,
templateUrl: 'index.html'
})
.state('index.list', {
url: '/list',
views: {
'list-index' : {
templateUrl: 'list.html',
controller: 'ListCtrl'
}
}
})
$urlRouterProvider.otherwise('/list');
})
我的index.html
只有一个
在body标签内
htmllist.html
有一些代码,通过使用conotrollerListCtrl
获取一些JSON内容来加载列表
应用程序加载为空白。
我需要被指向正确的方向。我认为我离正确的解决方案太近了。非常感谢您的帮助。谢谢
添加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="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.4.2.min.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-nav-view name='list-index'></ion-nav-view>
</body>
</html>
链接到app.js
-你能描述一下你的爱奥尼亚应用程序目录结构吗
应为:
PROJECT
- hooks
- platforms
- www
- js <=== this dir includes all your js in ionic structure.
- templates/ <== this is a dir that includes all html templates in ionic structure
- index.html <== THIS IS THE STARTING POINT OF YOUR PROJECT, CONTAINING angularJS script and ng-app for exemple
如果您将templateURl保留为templateURl:'index.html'
,那么我假设您将与主index.html冲突。。。。坏主意。是的,我想要我的主文件index.html作为父容器。我没有一个名为templates的文件夹,所以我在文件夹www.My app.js中有两个文件。如果你没有templates文件夹,那么为什么要将templateUrl命名为“templates/list”。我没有,请检查我在问题上发布的代码。必须有一个名为templates?的文件夹,添加了文件夹结构。添加了代码。我还检查了你的最新答案。我不明白为什么必须有一个templates
文件夹。我们不能在不创建文件夹的情况下完成这项工作吗?您有任何javascript错误吗?您可以通过运行应用程序ionic service
并检查chrome中的开发人员工具来检查
$stateProvider
.state('index', {
url: '/',
abstract: true,
templateUrl: 'templates/index.html'
})
.state('index.list', {
url: '/list',
views: {
'list-index' : {
templateUrl: 'templates/list.html',
controller: 'ListCtrl'
}
}
})