Angular路由实现单页面切换

html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Angular路由实现单页面切换title>
    <script src="AngularJS/angular.js">script>
    <script src="AngularJS/angular-route.js">script>
    <script type="text/javascript">
        var app = angular.module("myApp",['ngRoute']);
        app.controller("myCtrl01",function ($scope,$route) {
            $scope.$route = $route;
        });
        app.controller("myCtrl02",function ($scope,$route) {
            $scope.$route = $route;
        });
        app.config(["$routeProvider",function ($routeProvider) {
            $routeProvider
                .when('/home',{
                    templateUrl:'home.html',
                    controller:'myCtrl01'
                })
                .when('/second',{
                    templateUrl:'second.html',
                    controller:'myCtrl02'
                })
                .otherwise({
                    redirectTo:'/home'
                });
        }]);
        app.controller("myCtrl",function ($scope) {

        });
    script>
head>
<body ng-app="myApp" ng-controller="myCtrl">
    <script type="text/ng-template" id="home.html">
        <h1>Homeh1>
    script>
    <script type="text/ng-template" id="second.html">
        <h1>Secondh1>
    script>
    <div>
        <a href="#/home">HOMEa>
        <a href="#/second">SECONDa>
    div>
    <div  ng-view style="width: 200px; height: 200px;border: 1px dashed blue">

    div>
body>
html>

你可能感兴趣的:(AngularJS)