Issue
I'm building an app to show the contents of a book. I have 3 pages in this app:
Page 1. List of buttons that links to chapters; (ChaptersPage
)
Page 2. List of buttons that links to pages of a chapter; (PagesPage
)
Page 3. Page content; (PageContentPage
)
Pages 1 and 2 are inside a Tab, so when the user selects a chapter he goes to the next tab, then select a page of the chapter and then get the page content. The tabs will look like this:
All pages and chapters are on his own folders. My app folders looks like this:
src
|_ app
|_ assets
|_ icon
|_ images
|_ chapters
|_ 1
|_page_1.txt
|_page_2.txt
|_ 2
|_page_1.txt
|_page_2.txt
|_ 3
|_page_1.txt
|_page_2.txt
|_ ...
|_ pages
|_ services
|_ ...
First, when the user selects a chapter I need to look how many pages are inside the chapter folder, so I can list the correct number of buttons. I'm trying to use ionic native File plugin but I have no success. Using the example on the file plugin doc I'm always getting "Directory doesnt exist":
this.file.checkDir(this.file.applicationDirectory, 'assets/chapters/2').then(_ =>
console.log('Directory exists')
).catch(err => console.log('Directory doesnt exist'));
So, my question is: how can I read how many files are inside a chapter folder? and after, how can I get the contents of a page.txt?
Solution
readPage() {
this.http.request('../assets/chapters/1/page_1.txt')
.map(res => res.text())
.subscribe(text => {
this.txtContent= text;
})
.catch(error => {
console.err("Path not found with error:", error);
});
}
Answered By - maninak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.