关于角1.5组件生命周期挂钩 [英] About Angular 1.5 component Lifecycle Hooks

查看:232
本文介绍了关于角1.5组件生命周期挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

角文档有关于组件的以下信息

The angular documentation has the following information regarding components

组件有一个定义良好的生命周期的每个组件可以实现生命周期挂钩。这些是将在某些点在组件的寿命被调用的方法。下面钩方法可以实现:$的OnInit() -
  $ onChanges(changesObj)$的onDestroy()
  $ postLink()

Components have a well-defined lifecycle Each component can implement "lifecycle hooks". These are methods that will be called at certain points in the life of the component. The following hook methods can be implemented: $onInit() - $onChanges(changesObj) $onDestroy() $postLink()

https://docs.angularjs.org/guide/component

我试图执行这些不同的方式,听着他们,但我似乎无法得到它的工作,我尝试不同的东西,像传递一个函数作为参数或分配的功能,使用 $范围, $关于这个无济于事。我试着阅读角源$ C ​​$ c和有关于它的信息非常少的。在这个文件中,<一个href=\"https://github.com/angular/angular.js/blob/71cf28cf06295e0936f706c048bc07e6c963acc4/src/ng/compile.js\"相对=nofollow> compile.js 线3202,它看起来像使用它们正确的方式来做到这一点是一个函数分配给它。

I have tried different ways to implement them, listening to them, but I can't seem to get it working, I tried different things, like passing a function as argument or assigning a function, tried using $scope, $on and this to no avail. I tried reading the angular source code and there's very little information about it. On this file, compile.js on line 3202 it looks like to use them the right way to do it is to assign a function to it.

任何信息都是AP preciated。

Any information is appreciated.

推荐答案

在写这个,我意识到,生命周期挂钩是不具备的角度1.5.0。它是在1.5.3近期推出。所以,如果有人正在使用它们必须升级到角的最新版本。

While writing this I realized that the lifecycle hooks were not available in angular 1.5.0. It was introduced recently in 1.5.3. So if anyone is looking to use them you must upgrade to a latest version of Angular.

这篇关于关于角1.5组件生命周期挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆