i'm new angularjs , want redirect application login.html homepage.html. i've read lot , found 2 ways that:
the first 1 consists in using $window.location.href
and works perfectly
the second 1 consist in using $location.url
or $location.path
and doesn't work, ad /homepage.html actual url.
how can solve this? here's code.
<!doctype html> <html> <head> <title>login</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script> </head> <body> <div ng-app="mainapp" ng-controller="logincontroller"> <label>username</label><input type="text" name="username" ng-model="username"><br> <label>password</label><input type="password" name="password" ng-model="password"><br> <button ng-click="login()">login</button> <p>{{result}}</p> </div> <script> var mainapp = angular.module("mainapp", []); mainapp.controller('logincontroller', ['$scope', '$location', function($scope, $location){ $scope.result = null; $scope.login = function(){ $scope.result = "logged in"; $location.path('#/localhost/homepage.html').replace(); $scope.apply(); } }]) </script> </body> </html>
thanks anticipatedly!
not sure if it's important or not, try changing $scope.apply()
$scope.$apply()
.
Comments
Post a Comment