Angular 监听路由变化
var app = angular.module('Mywind',['ui.router'])
//Angular 监听路由变化
function run($ionicPlatform, $location, Service, $rootScope, $stateParams) {
//路由监听事件
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams) {
console.log(event);
console.log(toState);
console.log(toParams);
console.log(fromState);
console.log(fromParams);
//判断当前路由
if (toState.name == "index1") {
//获取参数之后可以调请求判断需要渲染什么页面,渲染不同的页面通过 $location 实现
if (toParams.id == 10) {
$location.path();//获取路由地址
$location.path('/validation').replace();
event.preventDefault()//可以阻止模板解析
}
}
})
// stateChangeSuccess 当模板解析完成后触发
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
})
// $stateChangeError 当模板解析过程中发生错误时触发
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
})
}
app.controller('Myautumn',function($scope,$http,$filter){
//执行路由事件
// $viewContentLoading- 当视图开始加载,DOM渲染完成之前触发,该事件将在$scope链上广播此事件。
$scope.$watch('$viewContentLoading',function(event, viewConfig){
// alert('模板加载完成前');
});
//$viewContentLoaded- 当视图加载完成,DOM渲染完成之后触发,视图所在的$scope发出该事件。
$scope.$watch('$viewContentLoaded',function(event){
// alert('模板加载完成后');
});
});
Angular 监听路由变化的更多相关文章
- Angular 监听路由变化事件
摘要: $stateChangeStart- 当模板开始解析之前触发 $rootScope.$on('$stateChangeStart', function(event, toState, toPa ...
- AngularJS监听路由变化
使用AngularJS时,当路由发生改变时,我们需要做某些处理,此时可以监听路由事件,常用的是$routeStartChange, $routeChangeSuccess.完整例子如下: <!D ...
- vue 如何通过监听路由变化给父级路由菜单添加active样式
1.项目需求:在项目开发中,多级菜单的情况下,勾选子菜单时,需要在父级菜单添加active样式. 2.遇到的问题:一级路由菜单的话,点击当前路由会自动在路由标签上添加router-link-exact ...
- angular 全局 监听路由变化
app.run(['$rootScope', '$location', function($rootScope, $location) { /* 监听路由的状态变化 */ $rootScope.$on ...
- mint ui的tabBar监听路由变化实现tabBar切换
说明 最近学习vue,使用了mint ui的tabBar,感觉好难受,结合 tab-container使用更难受,因为它不是根据路由来切换页面的.mui与它基本相反,因此它能根据搜索栏的路由变化,相应 ...
- 【转载】AngularJS监听路由变化
一.Angular 路由状态发生改变时可以通过' $stateChangeStart '.' $stateChangeSuccess '.' $stateChangeError '监听,通过注入'$l ...
- vue 监听路由变化
方法一:通过 watch // 监听,当路由发生变化的时候执行 watch:{ $route(to,from){ console.log(to.path); } }, 或 // 监听,当路由发生变化的 ...
- vue监听路由变化
使用 watch,观察路由,一旦发生变化便重新获取数据 watch: { // 如果路由有变化,会再次执行该方法 '$route': 'fetchData' }
- vue页面内监听路由变化
beforeRouteEnter (to, from, next) { // 在渲染该组件的对应路由被 confirm 前调用 // 不!能!获取组件实例 `this` // 因为当钩子执行前,组件实 ...
随机推荐
- ruby OpenURI模块使用
OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP(OpenURI支持重定向) 像打开普通文件那样打开ht ...
- anaconda 安装opencv win10
直接在命令窗口里面运行:pip install opencv-python即可.
- 003---设计首页index页面
在项目的urls.py文件添加一条url from django.contrib import admin from django.urls import path, re_path from app ...
- C语言数据结构(二)
算法和算法的衡量 一.算法 算法是为了解决某类问题而规定的一个有限长的操作序列.一个算法必须满足以下五个重要特性: 1.有穷性 对于任意一组合法输入值,在执行又穷步骤之后一定能结束,即:算法中的每 ...
- Python字符串处理:过滤字符串中的英文与符号,保留汉字
使用Python 的re模块,re模块提供了re.sub用于替换字符串中的匹配项. re.sub(pattern, repl, string, count=0) 参数说明: pattern:正则重的模 ...
- EF更新时出错,An error occurred while updating the entries. See the inner exception for details
在使用EF进行更新数据时出错,报出的异常是 "An error occurred while updating the entries. See the inner excep ...
- Oracle physical dataguard with broker部署
一.环境说明 主库:10.110.96.88 备库:10.110.96.87 数据库实例:gisc 二.主库操作 1.开启force logging ALTER DATABASE FORCE LOGG ...
- browsersync的安装与基本使用
browser-sync启动命令 Browsersync能让浏览器实时.快速响应您的文件更改(html.js.css.sass.less等)并自动刷新页面. 官网文档:http://www.brows ...
- Gym101981I Magic Potion(最大流)
Problem I. Magic Potion There are n heroes and m monsters living in an island. The monsters became v ...
- 1013 Battle Over Cities (25 分)(图的遍历or并查集)
这题用并查集或者dfs都可以做 dfs #include<bits/stdc++.h> using namespace std; ; bool mp[N][N]; int n,m,k; b ...