단일 페이지 전환을 위한 Angular 라우팅

13963 단어 AngularJS
/span>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>

좋은 웹페이지 즐겨찾기