I am using angularJs for my webApp, but i used $stateProvider
everywhere to define state.so now I want to use $routeProvider
instead of $stateProvider
.and how I change the route? is $location is good to change the path ?
This is my trial code with $routeProvider
angular.module("angular.states", [])
.config(['$routeProvider', '$locationProvider', '$stateProvider'], function ($stateProvider, templateRoot, $routeProvider) {
$routeProvider.when('/login?username&message&error', {
'templateUrl': '/templates/login.html',
'controller': 'LoginController'
});
$routeProvider.when('/logout', {
'templateUrl': '/templates/logout.html',
'controller': 'LogoutController'
});
})
.controller('LoginController', function (UserService, $scope, $state, $stateParams, AuthFactory, $timeout, $location) {
$scope.login = function (username, password) {
UserService.login({
'username': username,
'password': password
});
};
})
.controller('LogoutController', function (UserService, $scope, $location) {
$scope.logout = function () {
UserService.logout({}, function () {
$location.path("/login", {
});
});
};
});
I am not sure about $routeProvider
, so please tell me how to use it