<html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script src="https://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> <script src="https://apps.bdimg.com/libs/angular-route/1.3.13/angular-route.js"></script> <script type="text/javascript"> angular.module('ngRouteExample', ['ngRoute']) .controller('HomeController', function ($scope) { $scope.$route = $route;}) .controller('AboutController', function ($scope) { $scope.$route = $route;}) .config(function ($routeProvider) { $routeProvider. when('/home', { templateUrl: 'embedded.home.html', controller: 'HomeController' }). when('/about', { templateUrl: 'embedded.about.html', controller: 'AboutController' }). otherwise({ redirectTo: '/home' }); }); </script> </head> <body ng-app="ngRouteExample"> <script type="text/ng-template"> <h1> Home </h1> </script> <script type="text/ng-template"> <h1> About </h1> </script> <div> <div> <a href="#/home">Home</a> <a href="#/about">About</a> </div> <div ng-view=""> </div> </div> </body> </html>
运行结果:
Home
以上就是对AngularJS 路由的资料整理,希望能帮助AngularJS 编程的同学。
您可能感兴趣的文章: