Так что я хотел расширить свой проект, чтобы лучше работать с мобильными устройствами и изменился с использования Angularjs на Ionic/Angular.I получил контроллер работает нормально, но почему-то мой $ stateProvider не реагирует вообще.Почему мой провайдер Ionic не работает?
это мои главные app.js
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'
});
})
Это мой controllers.js я только проверил, что мой testController работает, хотя, когда $ state.go («/ Войти») называется он дает ошибку, ошибка: не удалось разрешить «/ логин» из состояние «»
angular.module('mainApp', ['ionic'])
.controller('mainController', function($scope, $state){
$scope.$state=$state;
})
.controller('frontpageController', function($scope){
$scope.test="frontpage";
})
.controller('testController', function($scope, $state){
$scope.test="hmm";
$scope.testi = function(){
$state.go('/login');
$scope.test="lol";
console.log('test');
};
})
.controller('loginController', function($scope, $http, $state){
$scope.rememberMe = false;
$scope.authenticate = function(user){
$scope.loginError = "";
$http.post('http://localhost:8080/api/authenticate', user)
.success(function(response) {
if (response.success === true){
$state.go("/frontpage");
console.log(response.msg);
}else if (response.success === false){
console.log(response.msg);
$scope.loginError = "login failed";
};
})
.error(function(response, status) {
alert('Error! ' + status + ' : ' + response);
});
};
})
.controller('registerController', function($scope, $http, $location){
$scope.register = function(user){
$scope.registerError = "";
if (user.password === user.repassword)
$http.post('http://localhost:8080/api/users', user)
.success(function(response) {
console.log(user);
})
.error(function(response, status) {
alert('Error! ' + status + ' : ' + response);
});
else
$scope.registerError = "passwords do not match";
}
});
на всякий случай вот мой 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>