I am new to angular js and trying to work with directives ng-viewand ngRoute.
I have loginPage.html in which I have login code written as follows
<button class="button button-block" ng-click="login()">Log In</button>
and when I click the button, the login function in loginController will be executed, and my controller will be 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() {
$http.post('/login', $scope.user).success(function(response) {
if(response.status == "true")
else
$scope.error="Invalid login! Please try again";
$scope.user.email="";
$scope.user.password="";
});
};
}]);
If response.status==true, then I want to change my view to /home. Can someone please tell me how to do this?
Thank.
source
share