角度教程route provider
明确调用以下内容,(为简洁起见进行了调整)
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'});
}]);
我们可以route provider
单独定义,然后通过angular directive
下面的方式调用它吗?是否存在这样的指令?否则,如何度过难关?
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