简体   繁体   English

使用Ionic3进行函数调用时出现运行时错误

[英]Runtime error in function calling using Ionic3

I am new in ionic. 我是离子新手。 I have made a popover. 我做了一个弹出窗口。 Now I want to make tab on popover. 现在,我想在弹出框上添加标签。 Here I used javascript tab from www.w3schools.com. 在这里,我使用了www.w3schools.com上的javascript标签。 It runs but when I click a tab it shows runtime error opencity function is not defined . 它运行,但是当我单击一个选项卡时,它显示运行时错误opencity函数未定义 How can I fix that? 我该如何解决?

popover.html popover.html

<!-- Generated template for the PopoverComponent component -->
<div class="bg-image" style="height: 300px;">
<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')">London</button>
  <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>

<div id="London" class="tabcontent">
  <h3>London</h3>
  <p>London is the capital city of England.</p>
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p> 
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>
</div>

popover.ts popover.ts

import { Component } from '@angular/core';


@Component({
 selector: 'popover',
  templateUrl: 'popover.html'
})

export class PopoverComponent {

 text: string;

constructor() {
console.log('Hello PopoverComponent Component');
this.text = 'Hello World';
}

}

function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}

In popover.html have to update onclick to (click) function like: 在popover.html中,必须将onclick更新为(click)函数,例如:

<!-- Generated template for the PopoverComponent component -->
  <div class="bg-image" style="height: 300px;">
    <div class="tab">
      <button class="tablinks" (click)="openCity(event, 'London')">London</button>
      <button class="tablinks" (click)="openCity(event, 'Paris')">Paris</button>
      <button class="tablinks" (click)="openCity(event, 'Tokyo')">Tokyo</button>
    </div>
    ....
  </div>

And popover.ts file like this, inside PopoverComponent class: 在PopoverComponent类中的popover.ts文件是这样的:

import { Component } from '@angular/core';
@Component({ selector: 'popover', templateUrl: 'popover.html' })

export class PopoverComponent {

    text: string;

    constructor() {
        console.log('Hello PopoverComponent Component');
        this.text = 'Hello World';
    }

    openCity(evt, cityName) {
        var i, tabcontent, tablinks;
        tabcontent = document.getElementsByClassName("tabcontent");
        for (i = 0; i < tabcontent.length; i++) {
            tabcontent[i].style.display = "none";
        }
        tablinks = document.getElementsByClassName("tablinks");
        for (i = 0; i < tablinks.length; i++) {
            tablinks[i].className = tablinks[i].className.replace(" active", "");
        }
        document.getElementById(cityName).style.display = "block";
        evt.currentTarget.className += " active";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用GET HTTP时,Android上的ionic3错误 - ionic3 error on android when calling GET HTTP 为什么在使用NgFor,访问Firebase,Ionic3和AngularFire时出现“预期功能”错误 - Why I get a “Function Expected” Error when using NgFor, accessing Firebase, Ionic3 and AngularFire 错误类型错误:Object(...) 不是函数/ionic3 乱舞分析插件 - ERROR TypeError: Object(...) is not a function / ionic3 flurry-analytics plugin 我将ionic2项目更新为ionic3时遇到运行时错误? - I am getting Runtime Error when I update ionic2 project to ionic3 ? Google在Ionic3中未定义错误 - Google is not defined error in Ionic3 离子-运行时错误:Object(…)不是函数 - Ionic - Runtime Error: Object(…) is not a function 从ionic3发布到php时,我在ionic 3中遇到错误:运行时错误JSON中位置0上的意外令牌&lt; - I am getting an error in ionic 3 : Runtime Error Unexpected token < in JSON at position 0 when posting to php from ionic3 通过ionic3调用wordpress用户api时CORS访问错误 - CORS Access error while calling wordpress user api via ionic3 Observable中的调用递归函数在ionic3中不起作用 - Call recursive function in Observable not working in ionic3 Ionic3 - 电子邮件编辑器 - Object(...) 不是函数 - Ionic3 - Email Composer - Object(...) is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM