Every time I use routers without controllers, they work perfectly fine. But the moment I add controllers to them, my routers stop working completely. Can someone please shed some light on what might be causing this issue with my router functions?
LOGIN CONTROLLER:
angular.module('starter', ['ionic'])
.controller('LoginCtrl', function($scope, LoginService, $ionicPopup, $state) {
$scope.login = function() {
console.log("LOGIN user: " + $scope.username + " - PW: " + $scope.password);
LoginService.loginUser($scope.username, $scope.password).success(function(data) {
console.log("Login Successful");
$state.go('home');
}).error(function(data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!'
})
})
}
});
ROUTERS CODE
angular.module('starter', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'page2.html',
controller: 'HomeCtrl'
})
.state('login', {
url: '/login',
templateUrl: 'index.html',
controller: 'LoginCtrl'
})
$urlRouterProvider.otherwise('/login');
});