Created
December 16, 2014 22:23
-
-
Save felquis/f83450d3d7cb0dcffbe0 to your computer and use it in GitHub Desktop.
Ionic report: problem with view events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html ng-app="ionicApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> | |
<title>Tabs Example</title> | |
<link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet"> | |
<script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script> | |
</head> | |
<body> | |
<ion-nav-bar class="bar-positive"> | |
<ion-nav-back-button class="button-icon ion-arrow-left-c"> | |
</ion-nav-back-button> | |
</ion-nav-bar> | |
<ion-nav-view></ion-nav-view> | |
<script id="templates/tabs.html" type="text/ng-template"> | |
<ion-tabs class="tabs-icon-top tabs-positive"> | |
<ion-tab title="Home" icon="ion-home" href="#/tab/home"> | |
<ion-nav-view name="home-tab"></ion-nav-view> | |
</ion-tab> | |
<ion-tab title="About" icon="ion-ios7-information" href="#/tab/about"> | |
<ion-nav-view name="about-tab"></ion-nav-view> | |
</ion-tab> | |
<ion-tab title="Contact" icon="ion-ios7-world" ui-sref="tabs.contact"> | |
<ion-nav-view name="contact-tab"></ion-nav-view> | |
</ion-tab> | |
</ion-tabs> | |
</script> | |
<script id="templates/home.html" type="text/ng-template"> | |
<ion-view view-title="Home"> | |
<ion-content class="padding"> | |
<!-- <a class="button icon icon-right ion-chevron-right" href="#/tab/facts">Scientific Facts</a> --> | |
<div class="list"> | |
<div class="item item-thumbnail-left full-width" | |
collection-repeat="item in feed track by $index" | |
collection-item-height="99" | |
ui-sref="tabs.profile({seed: item.seed})"> | |
<img ng-src="{{ item.user.picture.medium }}" /> | |
<h2>{{ $index }} - {{ item.user.name.first }} {{ item.user.name.last }}</h2> | |
<p>@{{ item.user.username }}</p> | |
</div> | |
</div> | |
</ion-content> | |
</ion-view> | |
</script> | |
<script id="templates/profile.html" type="text/ng-template"> | |
<ion-view view-title="{{ profile.user.username }}"> | |
<ion-content class="padding"> | |
<img ng-src="{{ profile.user.picture.thumbnail }}" /> | |
<h2>{{ profile.user.thumbnail }}</h2> | |
<p>{{ profile.user.phone }}</p> | |
<hr /> | |
<div class="list"> | |
<div class="item item-thumbnail-left full-width" | |
collection-repeat="item in feed track by $index" | |
collection-item-height="99" | |
ui-sref="tabs.profile({seed: item.seed})"> | |
<img ng-src="{{ item.user.picture.medium }}" /> | |
<h2>{{ $index }} - {{ item.user.name.first }} {{ item.user.name.last }}</h2> | |
<p>@{{ item.user.username }}</p> | |
</div> | |
</div> | |
</ion-content> | |
</ion-view> | |
</script> | |
<script id="templates/facts2.html" type="text/ng-template"> | |
<ion-view view-title="Also Factual"> | |
<ion-content class="padding"> | |
<p>111,111,111 x 111,111,111 = 12,345,678,987,654,321</p> | |
<p>1 in every 4 Americans has appeared on T.V.</p> | |
<p>11% of the world is left-handed.</p> | |
<p>1 in 8 Americans has worked at a McDonalds restaurant.</p> | |
<p>$283,200 is the absolute highest amount of money you can win on Jeopardy.</p> | |
<p>101 Dalmatians, Peter Pan, Lady and the Tramp, and Mulan are the only Disney cartoons where both parents are present and don't die throughout the movie.</p> | |
<p> | |
<a class="button icon ion-home" href="#/tab/home"> Home</a> | |
<a class="button icon ion-chevron-left" href="#/tab/facts"> Scientific Facts</a> | |
</p> | |
</ion-content> | |
</ion-view> | |
</script> | |
<script id="templates/about.html" type="text/ng-template"> | |
<ion-view view-title="About"> | |
<ion-content class="padding"> | |
<h3>Create hybrid mobile apps with the web technologies you love.</h3> | |
<p>Free and open source, Ionic offers a library of mobile-optimized HTML, CSS and JS components for building highly interactive apps.</p> | |
<p>Built with Sass and optimized for AngularJS.</p> | |
<p> | |
<a class="button icon icon-right ion-chevron-right" href="#/tab/navstack">Tabs Nav Stack</a> | |
</p> | |
</ion-content> | |
</ion-view> | |
</script> | |
<script id="templates/nav-stack.html" type="text/ng-template"> | |
<ion-view view-title="Tab Nav Stack"> | |
<ion-content class="padding"> | |
<p><img src="http://ionicframework.com/img/diagrams/tabs-nav-stack.png" style="width:100%"></p> | |
</ion-content> | |
</ion-view> | |
</script> | |
<script id="templates/contact.html" type="text/ng-template"> | |
<ion-view title="Contact"> | |
<ion-content> | |
<div class="list"> | |
<div class="item"> | |
@IonicFramework | |
</div> | |
<div class="item"> | |
@DriftyTeam | |
</div> | |
</div> | |
</ion-content> | |
</ion-view> | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ionicApp', ['ionic']) | |
.config(function($stateProvider, $urlRouterProvider) { | |
$stateProvider | |
.state('tabs', { | |
url: "/tab", | |
abstract: true, | |
views: { | |
'': { | |
templateUrl: 'templates/tabs.html' | |
} | |
} | |
}) | |
.state('tabs.home', { | |
url: "/home", | |
views: { | |
'home-tab': { | |
templateUrl: "templates/home.html", | |
controller: 'HomeTabCtrl' | |
} | |
} | |
}) | |
.state('tabs.profile', { | |
url: "/profile/:seed/", | |
views: { | |
'home-tab': { | |
templateUrl: "templates/profile.html", | |
controller: 'ProfileTabCtrl' | |
} | |
} | |
}) | |
.state('tabs.facts2', { | |
url: "/facts2", | |
views: { | |
'home-tab': { | |
templateUrl: "templates/facts2.html", | |
controller: 'Facts2TabCtrl' | |
} | |
} | |
}) | |
.state('tabs.about', { | |
url: "/about", | |
views: { | |
'about-tab': { | |
templateUrl: "templates/about.html", | |
controller: 'AboutTabCtrl' | |
} | |
} | |
}) | |
.state('tabs.navstack', { | |
url: "/navstack", | |
views: { | |
'about-tab': { | |
templateUrl: "templates/nav-stack.html", | |
controller: 'NavTabCtrl' | |
} | |
} | |
}) | |
.state('tabs.contact', { | |
url: "/contact", | |
views: { | |
'contact-tab': { | |
templateUrl: "templates/contact.html", | |
controller: 'ContactTabCtrl' | |
} | |
} | |
}); | |
$urlRouterProvider.otherwise("/tab/home"); | |
}) | |
.controller('HomeTabCtrl', function($scope, $randomUser, $test) { | |
$scope.loadMoreData = function () { | |
console.log('loadMoreData'); | |
$randomUser.get().then(function (data) { | |
console.log('Loaded MoreData'); | |
$scope.feed = $scope.feed.concat(data.slice(0, 10)); | |
$scope.$broadcast('scroll.infiniteScrollComplete'); | |
}, function () { | |
console.log('Error Loading MoreData'); | |
$scope.$broadcast('scroll.infiniteScrollComplete'); | |
}); | |
}; | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
console.log(data); | |
}); | |
$test.init(); | |
$scope.$on('$ionicView.loaded', function (viewInfo, state) { | |
console.log('CTRL - $ionicView.loaded', viewInfo, state); | |
}); | |
$scope.$on('$ionicView.unloaded', function (viewInfo, state) { | |
console.log('CTRL - $ionicView.unloaded', viewInfo, state); | |
}); | |
}) | |
.controller('ProfileTabCtrl', function($scope, $state, $randomUser) { | |
$scope.profile = $randomUser.getSeed($state.params.seed)[0]; | |
console.log('ProfileTabCtrl', $state.params.seed, $scope.profile); | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
console.log(data); | |
}); | |
}) | |
.controller('Facts2TabCtrl', function($scope, $randomUser) { | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
}); | |
console.log('Facts2TabCtrl'); | |
}) | |
.controller('AboutTabCtrl', function($scope, $randomUser) { | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
}); | |
console.log('AboutTabCtrl'); | |
}) | |
.controller('ContactTabCtrl', function($scope, $randomUser) { | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
}); | |
console.log('ContactTabCtrl'); | |
}) | |
.controller('NavTabCtrl', function($scope, $randomUser) { | |
$randomUser.get().then(function (data) { | |
$scope.feed = data; | |
}); | |
console.log('NavTabCtrl'); | |
}) | |
.service('$test', function ($rootScope) { | |
$rootScope.$on('$ionicView.loaded', function (viewInfo, state) { | |
console.log('SERVICE - $ionicView.loaded', viewInfo, state); | |
}); | |
$rootScope.$on('$ionicView.unloaded', function (viewInfo, state) { | |
console.log('SERVICE - $ionicView.unloaded', viewInfo, state); | |
}); | |
return { | |
init: function () { | |
console.log('Service Init'); | |
} | |
} | |
}) | |
/*** | |
Get data from randomuser.me and save it on localStorage | |
http://randomuser.me/ | |
***/ | |
.service('$randomUser', function ($q, $http, $filter) { | |
var randomuserMe = angular.fromJson(localStorage.randomuserMe) || {} | |
randomuserMe = randomuserMe.results || []; | |
return { | |
get: function () { | |
var deferred = $q.defer(); | |
if (randomuserMe.length > 0) { | |
deferred.resolve(randomuserMe); | |
return deferred.promise; | |
} | |
$http({ | |
method: 'get', | |
url: 'http://api.randomuser.me/?lego&results=40' // 40 is the max | |
}).success(function (data) { | |
localStorage.randomuserMe = angular.toJson(data); | |
deferred.resolve(data.results); | |
}).error(function (error) { | |
deferred.reject(error); | |
}); | |
return deferred.promise; | |
}, | |
getSeed: function (seed) { | |
return $filter('filter')(randomuserMe, { seed: seed }); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.full-width { | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment