angular ng-route路由相关参数配置
发布时间:2020-12-17 08:49:17 所属栏目:安全 来源:网络整理
导读:AngularJS 路由允许我们通过不同的 URL 访问不同的内容。 通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA)。 通常我们的URL形式为 http://runoob.com/first/page,但在单页Web应用中 AngularJS 通过 #! 标记 实现,例如:
AngularJS 路由允许我们通过不同的 URL 访问不同的内容。通过 AngularJS 可以实现多视图的单页Web应用(single page web application,SPA)。 通常我们的URL形式为 http://runoob.com/first/page,但在单页Web应用中 AngularJS 通过 #! 标记 实现,例如: 127.0.0.1:8080/#!/index 127.0.0.1:8080/#!/list 127.0.0.1:8080/#!/article
文件准备
当前html下<body ng-app="myApp"> <a href="#!/index">首页</a> <a href="#!/list">列表页</a> <div ng-view></div> <script src="node_modules/angular/angular.js"></script> <script src="node_modules/angular-route/angular-route.js"></script> <script> var app = angular.module('myApp',['ngRoute']); // angularjs是根据形参的名字去传递参数的 app.config(function($routeProvider){ // 路由的具体配置需要写在这个函数当中 // 当...时候 $routeProvider .when("/index",{ templateUrl:'./tpl/index.html',controller:'indexCtrl' }) .when("/list",{ templateUrl:'./tpl/list.html',controller:'listCtrl' }) //参数占位符 .when("/article/:id/:title",{ templateUrl:'./tpl/article.html',controller:'articleCtrl' }) // .otherwise('/index') otherwise({ //或者重定向也可以 redirectTo: '/home' }); }) app.controller('indexCtrl',function($scope){ $scope.msg = "我是首页中的数据"; }) app.controller('listCtrl',function($scope){ $scope.msg = "我是列表页中的数据"; }) app.controller('articleCtrl',function($scope,$routeParams){ console.log($routeParams.id); console.log($routeParams.title); }); </script> </body> 总结:以上只是angular路由最基本的思想的小demo,体会angular单页面的实现方式 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Axis2调用webService服务(调用而非发布)
- 根据路径动态更改bash提示符
- php – Apache docker container – 无效命令’RewriteE
- elasticsearch – 在Docker容器中保留弹性搜索数据
- Docker基础知识之Linux namespace图文详解
- 数组 – 如何使用变量在bash中索引${array [*]}?
- axis部署WebServices 和 JAXB的运用 (一)
- angularjs – 注入动态html似乎没有编译
- scala – 带有Http4s的Circe编码器和解码器
- 在_servicename_中的下划线是什么意思在AngularJS测试?