目前我需要在CheckSocialMedia函数中向浏览器添加一个事件。但是它说无法找到名字。
那么如何制作浏览器' .ts文件中的变量global?我尝试了一些东西,但没有任何工作。感谢
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { InAppBrowser, InAppBrowserOptions } from "@ionic-native/in-app-browser";
import { Platform } from 'ionic-angular';
import { AppAvailability } from '@ionic-native/app-availability';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public browser: object//doesn't work
constructor(public navCtrl: NavController, private inAppBrowser: InAppBrowser, public platform: Platform, private appAvailability: AppAvailability)
{
//options for iab
const options: InAppBrowserOptions =
{
toolbar: 'no',
location: 'no',
zoom: 'no'
}
//when device rdy
this.platform.ready().then( () => {
browser = this.inAppBrowser.create("https://www.awebsite.co.uk/", '_blank', options);
browser.on('loadstart').subscribe(event => { this.CheckSocialMediaLinks(event.url); });
})
}
//check if link is for social media
CheckSocialMediaLinks(url: string){ //I need to resubscribe the event
const watch = browser.on('loadstart').subscribe(event => { this.CheckSocialMediaLinks(event.url); });
}
答案 0 :(得分:1)
或者再举一个例子来解决这个全局问题。 https://forum.ionicframework.com/t/how-to-change-value-of-global-variable-on-any-files-in-ionic/103294/5?u=tomstumshais