Hi Kahna, You can inject it directly on controllers, I've made an example... http://codepen.io/huggaf/pen/jPpwKE
On Fri, Jul 17, 2015 at 8:45 AM, <[email protected]> wrote: > Hi, > > I am new to AngularJS and would like to figure out, how can I put all > constants to one place in AnguarJS app. > > How can I put constants to config.js and inject those values into Page > controller? > > Thanks in advance > > My application is structured as follows: > > config.js > > (function() { > 'use strict'; > angular.module('myapp') > .config(['$httpProvider', function ($httpProvider) { > //Reset headers to avoid OPTIONS request (aka preflight) > $httpProvider.defaults.headers.common = {}; > $httpProvider.defaults.headers.post = {}; > $httpProvider.defaults.headers.put = {}; > $httpProvider.defaults.headers.patch = {}; > }]) > .constant('PAGE_URL', { > root: '/' > }) > .constant('TEMPLATE_URL', { > home: 'app/home/home.html' > }); > })(); > > index.js > > 'use strict'; > angular.module('myapp', ['myapp.core','myapp.templates','ui.router', > 'ui.bootstrap', > 'angularChart', 'angularjs-dropdown-multiselect', 'smart-table', > 'angularModalService']); > angular.module('myapp') > .config(ConfigRoutes); > /* @ngInject */ > function ConfigRoutes($stateProvider, $urlRouterProvider, $injector) { > var pageURL = $injector.get('PAGE_URL'); > var templateURL = $injector.get('TEMPLATE_URL'); > > $stateProvider.state('/', { > url: pageURL.root, > templateUrl: templateURL.home, > controller: 'HomeController', > controllerAs: 'HomeController' > }); > > $urlRouterProvider.otherwise(pageURL.root); > } > > Page1 controller (partial) > (function() { > 'use strict'; > angular.module('myapp').controller('Page1Controller', ['$scope', > '$filter', '$modal', > 'Page1Service', 'Utility', Page1Controller]); > > function Page1Controller( > $scope, > $filter, > $modal, > Page1Service, > Utility) { > ... > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
