Skip to content

Instantly share code, notes, and snippets.

@arterzatij
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save arterzatij/e08309b60e69a8e75589 to your computer and use it in GitHub Desktop.
Save arterzatij/e08309b60e69a8e75589 to your computer and use it in GitHub Desktop.
Injeccion de constantes
// Declaracion del modulo de configuracion
angular
.module( 'dashboard.config', [] )
.constant( 'base_url' , 'http://www.domain.com/api' )
.constant( 'default_page', 'home' )
.constant( 'db_pages', [
{
name: 'statisticsOverview',
label: 'Dashboard',
icon: 'dashboard'
},
{
name: 'products',
label: 'Productos',
icon: 'product'
},
{
name: 'tags',
label: 'Tags',
icon: 'tag'
}
]);
// Declaracion del modulo de controladores
angular
//Inyeccion del modulo de configuracion en la declaracion del modulo
.module( 'dashboard.controllers', [ 'dashboard.config' ])
//Inyectamos la constante a querer utilizar del modulo de config
.controller('NavigationController', [
'$scope', 'default_page', 'db_pages',
function ( $scope, default_page, db_pages ) {
$scope.pages = db_pages;
$scope.db_page = default_page;
$scope.setActive = function ( page ) {
$scope.db_page = page;
}
$scope.isActive = function ( page ) {
return $scope.db_page === page;
}
}])
// Declaracion del modulo de servicios
angular
//Inyeccion del modulo de configuracion en la declaracion del modulo
.module( 'dashboard.services', [ 'dashboard.config' ])
//Inyectamos la constante a querer utilizar del modulo de config
.factory( 'Products', [ '$http', 'base_url', function( $http, base_url ){
//Codigo usando base_url
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment