AngularJs1.X学习--路由

本文详细介绍了AngularJS中三种不同的路由参数配置方式及其使用场景,包括如何在HTML中使用链接,以及如何在JavaScript中获取这些参数。此外还特别提到了参数在页面刷新后的表现差异。

【三种使用说明:】

$stateProvider.state('station.printQRCode', {
                //params: { 'parentOfficeId': null }, //一次性参数---printQRCode
                //url: '/printQRCode?:parentOfficeId', //URL参数--printQRCode?parentOfficeId=1
                url: '/printQRCode/:parentOfficeId', //URL参数--printQRCode/1 
                templateUrl: '~/App/station/views/stationsmanagement/printQRCode.cshtml'
            });
  • params: { 'parentOfficeId': null }        (http(s)://*****/printQRCode)

       使用这种方式,路由到的目标页面,只能在第一次加载的时候获取到参数值;一刷新页面,该参数值就不存在了! 

  • url: '/printQRCode?:parentOfficeId'       (http(s)://*****/printQRCode?parentOfficeId=10)
  • url: '/printQRCode/:parentOfficeId'       (http(s)://*****/printQRCode/10)

 

【html页面中使用:】

  <a ui-sref="station.printQRCode({parentOfficeId:{{vm.pOfficeId}}})"><i class="fa fa-plus"></i> @L("PrintQRCode")</a>

 

【Js文件中获取参数的方式:】

(function () {
    appModule.controller('cdode', [
        '$scope', '$stateParams',function ($scope, $stateParams) {            
         vm.parentOfficeId = ($stateParams.parentOfficeId || ""); //获取参数
 } ]); 
})();

 

注意:多参数后续遇到再补充:)

转载于:https://www.cnblogs.com/lishidefengchen/p/7055144.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值