I am new to angular js and trying to work with ng-view
and ngRoute
directives.
I have a loginPage.html in which i have code for login button written as follows
<button class="button button-block" ng-click="login()">Log In</button>
and on clicking the button the login function in loginController will get executed and my controller is written as follows:
var App = angular.module('App', ['ngRoute']);
App.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'loginPage.html',
controller: 'loginController'
}).
when('/home', {
templateUrl: 'homePage.html',
controller: 'homeController'
});
}]);
App.controller('loginController', ['$scope', '$http', '$location', function($scope, $http) {
console.log("Hello from login controller");
$scope.login = function() {
//console.log($scope.user);
$http.post('/login', $scope.user).success(function(response) {
if(response.status == "true")
//if the response is true i want to go to homepage.html.
else
$scope.error="Invalid login! Please try again";
$scope.user.email="";
$scope.user.password="";
});
};
}]);
If the response.status==true
then i want to change my view to /home
. Can someone please tell me how to do that?
Thank You.