Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aaronksaunders/23e9c7e71528666bcf85 to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/23e9c7e71528666bcf85 to your computer and use it in GitHub Desktop.
Demo ui-router basic state change
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link href="http://code.ionicframework.com/1.0.0/css/ionic.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.0.0/js/ionic.bundle.js"></script>
</head>
<body ng-app="app">
<ion-nav-bar class='bar-positive'>
<ion-nav-back-button class="button-clear">
<i class="ion-arrow-left-c"></i> Back
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view animation="slide-left-right"></ion-nav-view>
<script type="text/ng-template" id="home.html">
<ion-view title="Home">
<ion-content class="padding">
<button class="button button-assertive" ui-sref="detail">
Goto State 'detail'
</button>
<pre class="padding">{{stateInfo | json}}</pre>
</ion-content>
</ion-view>
</script>
<script type="text/ng-template" id="detail.html">
<ion-view title="Detail">
<ion-content class="padding">
<pre class="padding">{{stateInfo | json}}</pre>
</ion-content>
</ion-view>
</script>
</body>
</html>
myApp = angular.module('app', ['ionic']);
myApp.config(function($stateProvider, $urlRouterProvider) {
//
// For any unmatched url, redirect to /state1
$urlRouterProvider.otherwise("/home");
//
// Now set up the states
$stateProvider
.state('home', {
url: "/home",
templateUrl: "home.html",
controller :"homeCtrl"
})
.state('detail', {
url: "/detail",
templateUrl: "detail.html",
controller :"detailCtrl"
});
})
.controller('homeCtrl', function($scope, $state) {
$scope.stateInfo = $state.current;
})
.controller('detailCtrl', function($scope, $state) {
$scope.stateInfo = $state.current;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment