在angular2中使用ng init的替代方法
我正在尝试构建一个ionic2应用程序。我想在检测到ibeacon时向用户发送通知。它在angularjs中使用此代码。我怎样才能像下面的代码那样使用angular2实现这一点在angular2中使用ng init的替代方法,angular,ionic2,ibeacon,Angular,Ionic2,Ibeacon,我正在尝试构建一个ionic2应用程序。我想在检测到ibeacon时向用户发送通知。它在angularjs中使用此代码。我怎样才能像下面的代码那样使用angular2实现这一点 <div class="row" ng-controller="Example1Controller" ng-init="add()"> 您应该在ngOnInit中调用它 export class yourComponents implements OnInit { ngOnInit() { this
<div class="row" ng-controller="Example1Controller" ng-init="add()">
您应该在ngOnInit中调用它
export class yourComponents implements OnInit {
ngOnInit() {
this.add();
}
}
您应该在ngOnInit中调用它
export class yourComponents implements OnInit {
ngOnInit() {
this.add();
}
}
基本上,在上面的代码ng controller
中,定义控制器部分,即angular2的.ts文件(构造函数),您可以从中调用任何方法或任何内容,angular2中还存在ngOnInit()
生命周期挂钩
有关更多信息,请参见此处
基本上,在上面的代码ng controller
中,定义控制器部分,即angular2的.ts文件(构造函数),您可以从中调用任何方法或任何内容,angular2中还存在ngOnInit()
生命周期挂钩
有关更多信息,请参见此处
在Angular2中,ng init用作“生命周期挂钩”,可以添加到组件中。您的组件需要实现OnInit,并且您需要执行的任何初始化都可以在ngOnInit方法内部执行 您可以阅读更多关于Angular2生命周期挂钩的信息,并在此处查看示例:
在Angular2中,ng init用作“生命周期挂钩”,可以添加到组件中。您的组件需要实现OnInit,并且您需要执行的任何初始化都可以在ngOnInit方法内部执行 您可以阅读更多关于Angular2生命周期挂钩的信息,并在此处查看示例:
导入OnInit指令并在组件类中实现它。然后可以使用生命周期挂钩。ngOnInit在构造函数之后调用
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
constructor() { }
ngOnInit() {
//your code
}
}
导入OnInit指令并在组件类中实现它。然后可以使用生命周期挂钩。ngOnInit在构造函数之后调用
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
constructor() { }
ngOnInit() {
//your code
}
}