【问题标题】:onclick is supposed to open a webpage in angular ionic but it doesnot worksonclick 应该以角度离子打开网页,但它不起作用
【发布时间】:2021-07-15 20:56:45
【问题描述】:

我正在将应用浏览器添加到 Angular 离子项目中。我创建了一个标签项目。 在选项卡 1 中,我显示了我们单击的按钮,并且必须在网络上打开一个新页面。 这是 tab1.page.html 的代码

<ion-header [translucent]="true">
  <ion-toolbar>
    <ion-title>
      Tab 1
    </ion-title>
  </ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
  <ion-header collapse="condense">
    <ion-toolbar>
      <ion-title size="large">Tab 1</ion-title>
    </ion-toolbar>
  </ion-header>
  <ion-button click="open()">Click here!</ion-button>   <--------error here
  <app-explore-container name="Tab 1 page"></app-explore-container>
</ion-content>

tab1.module.ts 的代码在这里

import { IonicModule } from '@ionic/angular';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Tab1Page } from './tab1.page';
import { ExploreContainerComponentModule } from '../explore-container/explore-container.module';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';

import { Tab1PageRoutingModule } from './tab1-routing.module';

@NgModule({
  imports: [
    IonicModule,
    CommonModule,
    FormsModule,
    ExploreContainerComponentModule,
    Tab1PageRoutingModule
  ],
  declarations: [Tab1Page]
})
export class Tab1PageModule {
  constructor(private iab: InAppBrowser) {}
   
  open(){
    const browser = this.iab.create('https://ionicframework.com/');
  browser.on('loadstart').subscribe(event => {
  });
  browser.on('exit').subscribe(event => {
    browser.close();
  });
  }
}

我只想打开单击按钮时提供的链接,但它不起作用

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

    您需要包装您的 click 操作以将其绑定到您正在调用的函数。

    试试这个:

    <ion-button (click)="open()">Click here!</ion-button>
    

    您还将您的方法添加到不正确的 tab1.module.ts 文件中。

    将您的 open() 函数和导入移动到 tab1.page.ts 文件并重试。

    【讨论】:

    • 您是否尝试通过按标签栏中的标签来启动浏览器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 2012-07-04
    相关资源
    最近更新 更多