Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angular2中使用ng init的替代方法_Angular_Ionic2_Ibeacon - Fatal编程技术网

在angular2中使用ng init的替代方法

在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

我正在尝试构建一个ionic2应用程序。我想在检测到ibeacon时向用户发送通知。它在angularjs中使用此代码。我怎样才能像下面的代码那样使用angular2实现这一点

<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
     }
    }