Wednesday, 15 June 2011

Angularjs MVC application, I cannot figure out why I'm getting an Unknown provider: $routeProvider <- $route -



Angularjs MVC application, I cannot figure out why I'm getting an Unknown provider: $routeProvider <- $route -

i'm working on application using angularjs routing. i've added ngroute dependancy, have confirmed angular-route.js file beingness loaded. still unknown provider error $routeprovided <- $route.

what missing?

i have 3 files app, loaded in order displayed below.

my application.js file

(function () { 'use strict'; var app = angular.module('myapp', [ // angular modules 'nganimate', // animations 'ngroute', // routing ]); app.run(['$route', '$rootscope', '$q', 'routemediator', function ($route, $rootscope, $q, routemediator) { routemediator.setroutinghandlers(); }]); })();

my route config file

(function () { 'use strict'; var app = angular.module('myapp'); // configure toastr toastr.options.timeout = 4000; toastr.options.positionclass = 'toast-bottom-right'; var events = { controlleractivatesuccess: 'controller.activatesuccess', spinnertoggle: 'spinner.toggle' }; var config = { apperrorprefix: '[error] ', //configure exceptionhandler decorator doctitle: 'error: ', events: events, version: '1.0.0' }; app.value('config', config); app.config(['$logprovider', function ($logprovider) { // turn debugging off/on (no info or warn) if ($logprovider.debugenabled) { $logprovider.debugenabled(true); } }]); app.config(['commonconfigprovider', function (cfg) { cfg.config.controlleractivatesuccessevent = config.events.controlleractivatesuccess; cfg.config.spinnertoggleevent = config.events.spinnertoggle; }]); })();

my config file

(function () { 'use strict'; var app = angular.module('myapp'); // collect routes app.constant('routes', getroutes()); // configure routes , route resolvers app.config(['$routeprovider', 'routes', routeconfigurator]); function routeconfigurator($routeprovider, routes) { alert('in route config'); routes.foreach(function (r) { $routeprovider.when(r.url, r.config); }); $routeprovider.otherwise({ redirectto: '/home.html' }); } // define routes function getroutes() { homecoming [ { url: '/', config: { title: 'home', templateurl: '/app/views/home.html', controller: 'homecontroller', controlleras: 'vm', settings: { nav: 1, content: '<i class="fa fa-dashboard"></i> home' } } } ]; } })();

if you're using recent verison of angular (1.2+), need download , include ngroute file in add-on angular.js, doesn't include these side providers anymore.

angularjs angularjs-ng-route

No comments:

Post a Comment