Skip to content

Instantly share code, notes, and snippets.

@eseceve
Created August 29, 2014 04:17
Show Gist options
  • Save eseceve/83ca1c94db811d36aa4c to your computer and use it in GitHub Desktop.
Save eseceve/83ca1c94db811d36aa4c to your computer and use it in GitHub Desktop.
Oscar demo
angular.module('ngBoilerplate', [
'templates-app',
'templates-common',
'ngBoilerplate.home',
'ngBoilerplate.about',
'ui.router'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
})
.controller('AppCtrl', function($scope, $q, $timeout) {
$scope.$on('$stateChangeSuccess', function(e, toState) {
if (angular.isDefined(toState.data.pageTitle)) {
$scope.pageTitle = toState.data.pageTitle + ' | ngBoilerplate' ;
}
});
function getFake() {
var deferred = $q.defer(),
fake_json = {
foo: 'bar'
};
$timeout(function() {
deferred.resolve(fake_json);
}, 1000);
return deferred.promise;
}
// var promise = $http.get('http://url', config);
var promise = getFake();
promise.then(function(json) {
if (json.foo === 'bar') {
$state.go('about');
} else {
$state.go('home');
}
}, function(e) {
console.log(e); // error
});
/**
$stateProvider.state(state_name, state_config);
$state.go() recibe el nombre del "state" (state_name) al que quieres ir.
mira en home.js L26:25
$http retorna una promesa, como la que puedes hacer con $q,
pero además trae los metodos success() y error()
*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment