F
F
faragly2015-07-15 20:47:02
Angular
faragly, 2015-07-15 20:47:02

How to bring your module settings into AngularJS?

Hello! There was a need to move the functionality into a separate module. At first I just wanted a directive, but 2 services were needed for it, and here's the actual question - there are settings, for example, url for the request, time in milliseconds between requests, and the like, I found such a thing ,

angular.module('ngMyControl').value('options', {...})
- for me it’s the same thing, it turns out in the config of the application that will connect the module, you can somehow re-set the config via $provide, is there any example of implementing such functionality? I ask like this
var myapp = angular.module('ngMyControl', []);
myapp.constant('MODULE_VERSION', '0.0.1');
  myapp.value('options', {});
 myapp.service('dataService', ['$http', 'options', function($http, options) {
    this.request = function (query, hasTail) {
      var params = {};
      console.log(options);
      params['query[]'] = query || [];
      if (angular.isDefined(hasTail) && hasTail && params['query[]'].length) params.hasTail = true;
      return $http.get('/api/Data', {
        dataType: 'jsonp',
        params: params
      });
    };
  }]);

But my console does not show anything, what am I doing wrong? How to make default options and use them inside the module, as well as set them from outside?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2015-07-15
@faragly

codepen.io/AMar4enko/pen/rVzaYY

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question