简单教程
提交运行
代码编辑器:
<!DOCTYPE html> <meta charset="utf-8"> <link href="/static/next/css/tryit.css?v=2017082407" rel="stylesheet"/> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script> <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular-route.min.js"></script> <body ng-app="ngRouteExample" class="ng-scope"> <div> <div id="navigation"> <a href="#/home">Home</a> <a href="#/about">About</a> </div> <div ng-view=""> </div> </div> <footer>简单教程,简单编程<br/>Copyright © 简单教程 www.twle.cn</footer> <script type="text/ng-template" id="embedded.home.html"> <h1> Home </h1> </script> <script type="text/ng-template" id="embedded.about.html"> <h1> About </h1> </script> <script> 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> </body>
运行结果: