angularjs路由改变的事件监听
来源:互联网 发布:linux服务器架构 编辑:程序博客网 时间:2024/05/17 06:58
* Created by qingyun on 16/10/24. */angular.module('myApp',['ngRoute']).config(['$routeProvider',function ($routeProvider) { $routeProvider.when('/home',{ templateUrl : "home.html", controller : "homeController" //该属性特点 : 列表 (对象中的key 值 )可以注入到控制器 中使用, // 如果key对应的值为字符串,那么字符串的值必须是服务的名字, // 如果是函数呢,函数的参数也必须是服务的名字 // resolve :{ // //这里面必须是服务的名字 不然会报错 // a :"b" // // } }); $routeProvider.when('/other',{ templateUrl : "other.html", controller : "otherController" }); $routeProvider.otherwise('/home');}]) .run(['$rootScope',function ($rootScope) { //路由开始切换 $rootScope.$on('$routeChangeStart',function (eve,next,current) { console.log('11111'); // 第一个参数 : 事件 //第二个参数 : 要切换到的路由; //第一次进入到该方法没有当前路由,第三个参数为undefined console.log(eve,next,current); }); $rootScope.$on('$routeChangeSuccess',function (eve,current,previous) { //路由切换成功 // 第一个参数 : 事件 // 第二个参数 当前路由 // 第三个参数 上一个切换过来的路由 第一次没有 console.log('2222222'); console.log(eve,previous,current) }); $rootScope.$on('$routeChangeError',function (eve,msg) { //路由切换失败(比如resolve中有错误等等 都会导致路由切换失败) console.log('3333333'); console.log(eve,msg) }); //当location.path 发生变化或者$location.url发生变化时触发 $rootScope.$on('$locationChangeStart',function (eve,msg) { console.log('4444444444') }); //当且仅当path或url 变化成功以后 会走 $rootScope.$on('$locationChangeSuccess',function (eve,msg) { console.log('5555555') }) }]).controller('homeController',['$scope','$location',function ($scope,$location) { $scope.goToOtherView =function () { $location.path('/other'); };}]).controller('otherController',['$scope','$location',function ($scope,$location) { $scope.goBack = function () { window.history.go(-1); };}]);
0 0
- angularjs路由改变的事件监听
- angularJS监听路由变化改变页面内容
- $watch--angularJs的监听事件
- angularJS添加事件监听
- ngRoute路由改变监听事件(1)+ui.router状态路由
- 实时监听textField的值改变事件
- angularJS $scope的$watch方法监听model改变
- 布局改变监听事件
- 布局改变监听事件
- AngularJS路由系列(2)--刷新、查看路由,路由事件和URL格式,获取路由参数,路由的Resolve
- angularjs中作用域事件的路由与广播
- Angular 监听路由变化事件
- 关于AngularJs中监听事件及脏循环的理解
- AngularJs的前端路由
- angularjs 路由的使用
- angularJS的路由ngRoute
- AngularJS 避繁就简的路由
- AngularJS的路由 系列
- Java中的switch-case语句
- ATSAMV7Xult板卡调试Nuttx系统----NuttX系统的编译
- 使用lambda输出容器元素
- Android 系统状态栏沉浸式/透明化完整解决方案
- python的bs的简单实例爬取58同城手机信息
- angularjs路由改变的事件监听
- Ubuntu中Source Insight的使用
- BadgeView(数字提醒)
- 高精度除法(高除高)
- 第2.1.8章 WEB系统最佳实践Spring文件配置之spring-email.xml
- OSG+TUIO osgRecipes之osgtuio
- C/C++ Windows API——多线程加锁与临界区域
- 利用Python实现简单的日记本
- 如何屏蔽违禁词语