Last active
August 29, 2015 14:08
-
-
Save arterzatij/e08309b60e69a8e75589 to your computer and use it in GitHub Desktop.
Injeccion de constantes
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
// 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