Angular for a route provider
angular tutorial calls route provider
explicitly below (adapt for brevity)
angular.module('myApp', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/myResource1',
{templateUrl: 'partials/myView1.html', controller: MyController1}).
when('/myResource2',
{templateUrl: 'partials/myView2.html', controller: MyController2}).
otherwise({redirectTo: '/index.html'});
}]);
Is it possible to define route provider
separately and then call it with angular directive
below? Is there such a directive? If not, how to deal with it?
function MyRouteProvider($routeProvider) {
$routeProvider.
when('/myResource1',
{templateUrl: 'partials/myView1.html', controller: MyController1}).
when('/myResource2',
{templateUrl: 'partials/myView2.html', controller: MyController2}).
otherwise({redirectTo: '/index.html'});
};
<html ng-app="myApp">
<head>
<script src="lib/angular.js"></script>
<script src="js/MyControllers.js"></script>
<script src="js/MyRouteProvider.js"></script>
</head>
<body ng-routeProvider="MyRouteProvider">
...
</body>
</html>
myApp
|__index.html
|__js
| |__MyControllers.js
| |__MyRouteProvider.js
|__partials
|__myView1.html
|__myView2.html
+1
source to share
No one has answered this question yet
See similar questions:
or similar: