Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to redirect to home.html on click of a button in index.html

index.html


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/home.js"></script>
</head> 
<body ng-app="starter">
<ion-pane>
  <ion-header-bar class="bar-royal">
    <h1 class="title">Index</h1>
  </ion-header-bar>
  <ion-content>
      <div ng-controller="LoginCtrl">
          <button ng-click="login()">Login</button>
      </div>
  </ion-content>
</ion-pane>
</body>
</html>

home.js

var VLogin = angular.module('starter', ['ionic']);
VLogin.controller('LoginCtrl', ['$scope','$location', function($scope, $location) {

$scope.login = function(){  
$location.path("#/home.html");
};
}]);

And here is the hierarchy of both files enter image description here $location.path() is not working. Where am I going wrong? TIA.

share|improve this question
    
Have you setted up your routes? – Khaled Awad Apr 3 '16 at 21:18

take a look here: http://learn.ionicframework.com/formulas/navigation-and-routing-part-1/

but the simple answer is that you should set up routes

$stateProvider.state('app', {
  url: '',
  templateUrl: 'app.html',
  controller: 'AppCtrl'
  }
}).state('login', {
  url: '/login',
  templateUrl: 'login.html',
  controller: 'LoginCtrl'
  }
})

and then I would recommend using the $state provider to do something like this

login.controller('LoginCtrl', function($scope, $state) {
  $state.go('app',{});
})

This is not the EXACT code, but an overview, I would recommed reading the link provided for additional information

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.