0

I am trying to make an app which can open to read epub files. So I have tried to import this Epub.js javascript library according to this article. I am done with the arrangements in the article. So with code below I am trying to use epub.js in my Ionic 2 app in windows 10 and chrome browser. But I am getting this error below. Why am I getting this error?

ecatalog.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {epubjs} from "epubjs";

@Component({
  selector: 'page-ecatalog',
  templateUrl: 'ecatalog.html'

})
export class EcatalogPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
    var Book = epubjs.ePub("../www/books/k1ecatalog.epub");
      Book.renderTo("area");
  }
}

ecatalog.html

<ion-content>
<div onclick="Book.prevPage();">‹</div>
<div id="area"></div>
<div onclick="Book.nextPage();">›</div>

</ion-content>

Error:

Runtime Error
Error in ./MyApp class MyApp - caused by: Cannot read property 'ePub' of undefined

Stack
TypeError: Cannot read property 'ePub' of undefined
    at new EcatalogPage (http ://192.16 8.33.11:8100/build/main.js:58587:66)
    at new Wrapper_EcatalogPage (/AppModule/EcatalogPage/wrapper.ngfactory.js:7:18)
    at CompiledTemplate.proxyViewClass.View_EcatalogPage_Host0.createInternal (/AppModule/EcatalogPage/host.ngfactory.js:15:26)
    at CompiledTemplate.proxyViewClass.AppView.createHostView (http: //192 .168.33.11:8100/build/main.js:99490:21)
    at CompiledTemplate.proxyViewClass.DebugAppView.createHostView...
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103

1 Answers1

1

You need to copy epubjs folder into src/assets and then reference necessary files in your src/index.html

<script src="assets/epubjs/build/epub.min.js"></script>
<script src="assets/epubjs/build/libs/zip.min.js"></script>

and then in you page:

declare var ePub: any;
let book = ePub("assets/books/moby-dick/");

https://github.com/janpio/ionic-epubjs