在Ionic项目上,我有一个TS函数应该显示HTML元素,问题是单击它时出现错误,提示它不是函数。
这是堆栈错误
TypeError: _co.UnfoldAchievement is not a function
at Object.eval [as handleEvent] (ng:///AppModule/TravelPage.ngfactory.js:67:35)
at handleEvent (http://localhost:8100/build/vendor.js:13963:155)
at callWithDebugContext (http://localhost:8100/build/vendor.js:15472:42)
at Object.debugHandleEvent [as handleEvent] (http://localhost:8100/build/vendor.js:15059:12)
at dispatchEvent (http://localhost:8100/build/vendor.js:10378:25)
at http://localhost:8100/build/vendor.js:11003:38
at HTMLDivElement.<anonymous> (http://localhost:8100/build/vendor.js:39492:53)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
这是我的离子设置
Ionic Framework: 3.9.2
Ionic App Scripts: 3.2.0
Angular Core: 5.2.11
Angular Compiler CLI: 5.2.11
Node: 8.11.3
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
这是我的代码。
import { NgModule } from '@angular/core';
import { Component } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { NavController } from 'ionic-angular';
import { TravelPage } from '../travel/travel';
@NgModule({
declarations: [
TravelPage,
],
imports: [
IonicPageModule.forChild(TravelPage),
],
})
@Component({
selector: 'page-travel',
templateUrl: 'travel.html'
})
export class TravelPageModule {
constructor(public navCtrl: NavController) {
}
UnfoldAchievement()
{
let achievement = document.getElementById("World-Explorer-Content");
achievement.style.display = "contents";
}
}
答案 0 :(得分:0)
因此,原来的问题是我使用的是.module.ts文件而不是.ts文件。找不到该函数,因为它在错误的文件中。