溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

AngularJS中ui-view傳參的示例分析

發(fā)布時間:2021-07-15 13:59:14 來源:億速云 閱讀:150 作者:小新 欄目:web開發(fā)

這篇文章主要介紹了AngularJS中ui-view傳參的示例分析,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Angular路由傳參

首頁

<!DOCTYPE html> 
<html ng-app="app"> 
<head> 
<title>路由傳參</title> 
 
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
<meta http-equiv="description" content="this is my page"> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
<link rel="stylesheet" href="../../plugins/bootstrap/css/bootstrap.min.css" rel="external nofollow" type="text/css"></link> 
</head> 
<body> 
<div class="container"> 
  <nav class="navbar navbar-default" role="navigation"> 
  <div class="container-fluid"> 
  <div class="navbar-header"> 
    <a class="navbar-brand" href="#" rel="external nofollow" >柳絮飛祭奠</a> 
  </div> 
  </div> 
</nav> 
</div> 
<div ng-click="go()" ng-controller="state_go_controller"> 
    $state.go傳參數(shù)</div> 
 <a ui-sref="param({index:'123'})">傳參數(shù)</a> 
 
<div ui-view></div> 
</body> 
<script type="text/javascript" src="../../plugins/angular/angular.min-1.4.6.js"></script> 
  <script type="text/javascript" src="../../plugins/angular/angular-ui-router-0.2.10.js"></script> 
<script type="text/javascript"> 
  var app=angular.module("app",['ui.router']); 
  app.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){ 
      $stateProvider.state('index1', { 
        url : '/index1', 
        templateUrl : '/Angular/uiview/param/index1.html' 
      }).state('param',{ 
        url:'/param/:index', 
        templateUrl: '/Angular/uiview/param/param.html' 
      }); 
      $urlRouterProvider.otherwise('/index1'); 
}]).config(function($sceProvider){ 
  $sceProvider.enabled(false); 
}); 
  app.controller("state_go_controller", function($state, $scope) { 
    $scope.go = function() { 
      $state.go('param', { 
        index : 42 
      }); 
    }; 
  }); 
app.controller("view1_controller",function($stateParams){ 
//接收參數(shù) 
  alert($stateParams.index); 
}); 
</script> 
</html>

跳轉(zhuǎn)頁

<div ng-controller="view1_controller"></div> 


 接收參數(shù) 
 </body>

運行

點擊跳轉(zhuǎn)就可以看到alert的參數(shù)。

感謝你能夠認真閱讀完這篇文章,希望小編分享的“AngularJS中ui-view傳參的示例分析”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI