首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用角度组件路由器时,如何检测组件的变化?

当使用角度组件路由器时,如何检测组件的变化?
EN

Stack Overflow用户
提问于 2015-12-08 05:45:17
回答 1查看 396关注 0票数 1

现在我正在使用ui-路由器来处理授权:

代码语言:javascript
复制
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {}

但是,从Angular1.5开始,我如何使用ngComponentRouter来实现这个功能呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 06:09:21

在新路由器中有组件生命周期挂钩

代码语言:javascript
复制
angular.module('app', [])
  .controller('MyController', ['user', '$http', MyController]);

function MyController(user, $http) {
  this.user = user;
  this.$http = $http;
}

// Before switching to a new component, this hook runs for 
// each active component in the app. If any of them 
// return false, a rejected promise, or a promise that resolves to false,
// the navigation is cancelled.

MyController.prototype.canActivate = function() {
  return this.user.isAdmin;
};

//This hook fires just before the nagivation finishes.

MyController.prototype.activate = function() {
  return this.bigFiles = this.$http.downloadBigFiles();
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34148854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档