物业类型' url'类型'事件'上不存在

时间:2017-03-23 12:01:00

标签: javascript angular typescript ionic-framework ionic2

我收到以下错误消息

[ts] Property type 'url' does not exist on type 'Event'.

any

这是我使用的TypeScript(JavaScript)

document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
      var ref = window.open(url, '_blank', 'location=yes');
      ref.addEventListener('loadstart', function(event) { });
      ref.addEventListener('loadstop', function(event) { });
      ref.addEventListener('loaderror', function(event) { alert( event.url ) });//Property type 'url' does not exist on type 'Event'.
    }

以下是我的导入

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';
import { Event } from '@angular/router';

请帮忙!

1 个答案:

答案 0 :(得分:5)

您的活动实际上是InAppBrowserEvent类型,因此请将其导入并使用它注释参数:

import { InAppBrowser, InAppBrowserEvent } from '@ionic-native/in-app-browser';
...
...
function onDeviceReady() {
  var ref = window.open(url, '_blank', 'location=yes');
  ref.addEventListener('loadstart', function(event) { });
  ref.addEventListener('loadstop', function(event) { });
  ref.addEventListener('loaderror', function(event: InAppBrowserEvent) { alert( event.url ) }); //InAppBrowserEvent has 'url' property
}