Javascript 为什么';我的离子状态提供者不能工作吗?
因此,我想扩展我的项目,更好地使用移动设备,并从使用Angularjs改为使用Ionic/Angular。我的控制器工作正常,但出于某种原因,我的$stateProvider根本没有反应 这是我的主要app.jsJavascript 为什么';我的离子状态提供者不能工作吗?,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,因此,我想扩展我的项目,更好地使用移动设备,并从使用Angularjs改为使用Ionic/Angular。我的控制器工作正常,但出于某种原因,我的$stateProvider根本没有反应 这是我的主要app.js angular.module('mainApp', ['ionic']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { if(window.cordova && wind
angular.module('mainApp', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
这是我的config.js,它似乎根本不起作用,尽管它没有向控制台提供任何错误。如果找不到模板,它不应该给出一个错误吗?或者如果它不能解决这个问题
angular.module('mainApp', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.
state('/frontpage', {
templateUrl: './views/frontpage.html',
controller: 'frontpageController',
activetab: 'frontpage'
}).
state('/login', {
templateUrl: './views/login.html',
controller: 'loginController',
activetab: 'login'
}).
state('/register', {
templateUrl: './views/register.html',
controller: 'registerController',
activetab: 'register'
}).
otherwise({
redirectTo: '/frontpage'
});
})
这是my controllers.js我只测试了我的testController是否工作,尽管调用$state.go('/login')时会出现错误,错误:无法从状态“”解析'/login'
以防万一,这里是我的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>saunaguard</title>
<link rel="manifest" href="manifest.json">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<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) -->
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/config.js"></script>
<script src="js/controllers.js"></script>
</head>
<body ng-app="mainApp">
<div ng-controller = "testController">
<ul id ="selection">
<li ng-class="{active: $state.current.activetab == 'frontpage'}"><a href ="#frontpage">Home</a></li>
<li ng-class="{active: $state.current.activetab == 'login'}"><a href ="#login">Login</a></li>
<li ng-class="{active: $state.current.activetab == 'register'}"><a href ="#register">Register</a></li>
</ul>
<button ng-click="testi()">Submit</button> {{test}}
</div>
<ion-nav-view>
<ion-pane>
<ion-content>
</ion-content>
</ion-pane>
</ion-nav-view>
</body>
</html>
萨那加德
提交{{test}
如我所见,您没有将您的状态添加到特定的导航视图中
例如,这就是侧菜单的工作方式
<ion-nav-view name="menuContent"></ion-nav-view>
我不想粘贴整个结构,这将帮助您弄清楚,或者只是获得侧菜单启动程序并查看导航视图
ionic start myApp sidemenu
比如说
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
</body>
.state('app.playlists', {
url: '/playlists',
views: {
'menuContent': {
templateUrl: 'templates/playlists.html',
controller: 'PlaylistsCtrl'
}
}
})
ionic start myApp sidemenu