angular多頁面切換傳遞參數

來源:互聯網
上載者:User

標籤:log   template   redirect   ram   access   char   config   name   oct   

<!DOCTYPE html><html lang="en" ng-app="myapp"><head>    <meta charset="UTF-8">    <title>Document</title>    <script src="../js/angularjs.js"></script>    <script src="../js/angular-route.min.js"></script>    <style type="text/css">        body{            font-size: 32px;        }        .show{            background: #eeeeee;            padding: 8px;            width: 500px;            margin:8px 0px;        }    </style></head><body><div>    <div ng-view></div></div></body><script>    var app=angular.module(‘myapp‘,[‘ngRoute‘]);    app.controller(‘sub1‘,function($scope){        $scope.students=students;    });    app.controller(‘sub2‘,function($scope,$routeParams){        for (var i = 0;i<students.length;i++) {            if(students[i].stuId==$routeParams.id){                $scope.dd=students[i];                break;            }                    }    });    app.config(function($routeProvider) {        $routeProvider        .when(‘/‘,{            controller:"sub1",            templateUrl:"sub1.html"        })        .when(‘/view/:id‘,{            controller:"sub2",            templateUrl:"sub2.html",            publicAccess:true        })        .otherwise({ redirectTo: ‘/‘ });    });    var students=[        {stuId:1,name:"張三1",sex:"女1",score:121},        {stuId:2,name:"張三2",sex:"女2",score:122},        {stuId:3,name:"張三3",sex:"女3",score:123},        {stuId:4,name:"張三4",sex:"女4",score:124}    ]</script></html>


<!--sub.html-->
<div ng-repeat="x in students" class="show"><a href="#view/{{x.stuId}}">{{x.name}}</a></div>
<!--sub2.html-->
<div class="show">    <div>學號:{{dd.stuId}}</div>    <div>姓名:{{dd.name}}</div>    <div>性別:{{dd.sex}}</div>    <div>分數:{{dd.score}}</div></div>

 

 

 

angular多頁面切換傳遞參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.