在angular2中使用ng-init的替代方法 [英] Alternative to use ng-init in angular2

查看:166
本文介绍了在angular2中使用ng-init的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建ionic2应用程序.我想在检测到ibeacon时向用户发送通知.它在angularjs中使用了此代码.像下面的代码一样,如何使用angular2做到这一点?

I'm trying to build an ionic2 application. I want to send notifications to users when ibeacon is detected. It worked with this code in angularjs. How can I do this with angular2 like the code below?

<div class="row"  ng-controller="Example1Controller" ng-init="add()">

推荐答案

<div class="row"  ng-controller="Example1Controller" ng-init="add()">

基本上在上面的代码ng-controller中定义了控制器部分,它是angular2的.ts文件(构造函数),您可以从那里调用任何方法或任何方法,而且angular2中还存在ngOnInit()生命周期挂钩.

Basically in above code ng-controller define the controller part which is .ts file (constructor) for angular2 you can call any method or anything from there, also there is ngOnInit() life cycle hook present in angular2.

有关更多信息,请参见此处

For more info see here also

构造函数与ngOnInit之间的区别

这篇关于在angular2中使用ng-init的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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