Skip to content

Instantly share code, notes, and snippets.

@mxmzb
Created November 22, 2015 03:33
Show Gist options
  • Select an option

  • Save mxmzb/24c63249531c440120b5 to your computer and use it in GitHub Desktop.

Select an option

Save mxmzb/24c63249531c440120b5 to your computer and use it in GitHub Desktop.
myapp ion-nav-view issue
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('myapp', ['ionic', 'myapp.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router, which uses the concept of states.
// Learn more here: https://github.com/angular-ui/ui-router.
// Set up the various states in which the app can be.
// Each state's controller can be found in controllers.js.
$stateProvider
// Set up an abstract state for the tabs directive:
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html',
controller: 'TabsCtrl'
})
.state('tab.categories_index', {
url: '/categories',
views: {
'categories-index': {
templateUrl: 'categories_index.html',
controller: 'CategoriesIndexCtrl'
}
}
})
.state('tab.categories_show', {
url: '/categories/:id',
views: {
'categories-show': {
templateUrl: 'categories_show.html',
controller: 'CategoriesShowCtrl'
}
}
})
.state('tab.exercises_index', {
url: '/exercises',
views: {
'exercises-index': {
templateUrl: 'templates/exercises/index.html',
controller: 'ExercisesIndexCtrl'
}
}
})
.state('tab.exercises_show', {
url: '/exercises/:id',
views: {
'exercises-show': {
templateUrl: 'templates/exercises/show.html',
controller: 'ExercisesShowCtrl'
}
}
})
// // If none of the above states are matched, use this as the fallback:
$urlRouterProvider.otherwise('/tab/categories');
})
<ion-view view-title="Categories" class="categories-index-page">
<ion-content>
<ion-list>
<ion-item title="{{category.name}}" ng-repeat="category in categories" class="item-category" href="#/tab/categories/{{ category.id }}">
{{ category.name }}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
<ion-view view-title="Category" class="categories-show-page">
<ion-content>
test
</ion-content>
</ion-view>
angular.module('myapp.controllers', ['ionic', 'myapp.services'])
.controller('TabsCtrl', function($scope) {
})
.controller('CategoriesIndexCtrl', function($scope, $http) {
$http.get('http://localhost:3000/api/categories').then(function(resp) {
console.log('Success', resp);
$scope.categories = resp.data
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
})
.controller('CategoriesShowCtrl', function($scope) {
$http.get('http://localhost:3000/api/exercises?category_ids=').then(function(resp) {
console.log('Success', resp);
$scope.category = resp.data
// For JSON responses, resp.data contains the result
}, function(err) {
console.error('ERR', err);
// err.status will contain the status code
})
})
<!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>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="myapp">
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment