路由提供者的Angular指令

时间:2013-04-12 09:24:59

标签: angularjs angularjs-directive

angular tutorial会在下方调用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

0 个答案:

没有答案