routes.js
angular .module('main') .config(config); config.$inject = ['$routeprovider', '$httpprovider']; function config($routeprovider){ $routeprovider .when('/', { templateurl:'main/views/landing.client.view.html', controller:'maincontroller', controlleras:'mainctrl', resolve: { orgtypes: orgtypes } }) .otherwise({ redirectto:'/' }); } function orgtypes($http){ return $http .get('emrsvs/orgtypes') .then(function successcallback(response){ return response; }, function errorcallback(error){ console.log(error); }); }
controller.js
angular .module('main') .controller('maincontroller', maincontroller); maincontroller.$inject = ['$rootscope', '$timeout', 'orgtypes']; function maincontroller($rootscope, $timeout, orgtypes){ var mainctrl = this; mainctrl.orgtypes = orgtypes; }
error
[$injector:unpr] unknown provider: orgtypesprovider <- orgtypes <- maincontroller
here injecting dependency 'orgtypes' route controller. produced unknown provider error. there wrong sysntax? can find mistake
you should include following code in routes.js , before orgtypes function definition
angular.module('main') .factory('orgtypes', orgtypes); orgtypes.$inject = ['$http']; /*you need apply following changes in controller*/ angular .module('main') .controller('maincontroller', maincontroller); maincontroller.$inject = ['$rootscope', '$timeout', 'orgtypes']; function maincontroller($rootscope, $timeout, orgtypes){ var mainctrl = this; orgtypes.then(function(response){ mainctrl.orgtypes = response; }) }
Comments
Post a Comment