angularjs - Defining routes for a angular module -
i have mainapp.js file , put code on it:
var mainapp = angular.module('mainapp', []); **//routes** mainapp.config(['$routeprovider', function ($routeprovider) { $routeprovider .when('/index', { templateurl: '/views/admin/index.html' } ); }]);
when run application without routes section, ok when add them mainapp.js file face $injector:modulerr error in browser.
i try clear browser cache, check html pages sure including mainapp.js file , replace codes these:
var mainapp = angular.module('mainapp', []).config(config); config.$inject = ['$routeprovider']; function config($routeprovider) { $provider .when('/index', { templateurl: '/views/admin/index.html' } ); }
but nothing happened , face error again.
can me?
thanks
you need inject ngroute dependency, refer angular-router library,
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
controller
var mainapp = angular.module('mainapp', [ngroute]).config(config);
Comments
Post a Comment