javascript - AngularJS provider not working as per styleguide -
i'm following john papa's angular1 styleguide , trying implement provider.
the provider per document looks this,
angular .module('blocks.router') .provider('routerhelper', routerhelperprovider); routerhelperprovider.$inject = ['$locationprovider', '$stateprovider', '$urlrouterprovider']; /* @nginject */ function routerhelperprovider($locationprovider, $stateprovider, $urlrouterprovider) { /* jshint validthis:true */ this.$get = routerhelper; $locationprovider.html5mode(true); routerhelper.$inject = ['$state']; /* @nginject */ function routerhelper($state) { var hasotherwise = false; var service = { configurestates: configurestates, getstates: getstates }; return service; /////////////// function configurestates(states, otherwisepath) { states.foreach(function(state) { $stateprovider.state(state.state, state.config); }); if (otherwisepath && !hasotherwise) { hasotherwise = true; $urlrouterprovider.otherwise(otherwisepath); } } function getstates() { return $state.get(); } } }
i've mocked basic version here on plnkr
my provider:
angular .module('plunker') .provider('random', function() { this.$get = helper; this.getx = function() { return 10; } function helper() { var provider = { getx: getx, gety: gety } return provider; function getx() { return 10; } function gety() { return 20; } } });
so, getx
works fine, gety
undefined.
fear, i'm missing trivial.
shouldn't adding gety
method too?
angular .module('plunker') .provider('random', function() { this.$get = helper; this.getx = function() { return 10; } this.gety = function() { return 10; } function helper() { var provider = { getx: getx, gety: gety } return provider; // not required after return statement, why need them? } });
Comments
Post a Comment