1
我有一個情況,我想在提供程序中調用函數(f1),然後從該函數(f1)我想調用頁面中的另一個函數。離子v2從提供者的調用者頁面調用函數
這是page1.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import {Utils} from '../../providers/utils';
@Component({
selector: 'page-page1',
templateUrl: 'page1.html'
})
export class Page1 {
//storage: any;
constructor(public navCtrl: NavController, public storage: Storage, public utils: Utils) {
}
test()
{
this.utils.testOut(this.ret);
}
ret()
{
console.log(this);
}
}
和Utils.ts代碼這是提供者:
import { Injectable } from '@angular/core';
import { Http , Headers} from '@angular/http';
/*
Generated class for the HttpHelper provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class Utils {
constructor(private http: Http, private applicationConstants: ApplicationConstants) {
//console.log('Hello utils Provider');
//this.http = http;
}
testOut(success:Function)
{
success();
}
}
但是當它再次進入page1.ts,它打印在console.log「undefined」 這意味着page1.ts不具備所有變量和函數。
任何人都可以幫忙嗎?
我導入,但是同樣的東西 –