BootWiki教程网
源代码:
点击运行
<html> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type"> <script src="//cdn.staticfile.net/angular.js/1.4.6/angular.min.js"></script> <script src="//cdn.staticfile.net/angular-route/1.7.0/angular-route.js"></script> <script type="text/javascript"> angular.module('ngRouteExample', ['ngRoute']) .controller('HomeController', function ($scope, $route) { $scope.$route = $route;}) .controller('AboutController', function ($scope, $route) { $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 class="ng-scope" ng-app="ngRouteExample"> <script id="embedded.home.html" type="text/ng-template"> <h1> Home </h1> </script> <script id="embedded.about.html" type="text/ng-template"> <h1> About </h1> </script> <div> <div id="navigation"> <a href="#/home">Home</a> <a href="#/about">About</a> </div> <div ng-view=""> </div> </div> </body> </html>
运行结果