0

enter image description here

showFile() {
    var fs = require('fs');
    var obj = fs.readFile('dic.txt', 'utf8');
    console.log(obj);
  }

  getItems(ev) {
    // Reset items back to all of the items
    this.initializeItems();

    // set val to the value of the ev target
    var val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.items = this.items.filter((item) => {
        this.showFile();
        return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
      })
    }
  }

I want to make a mobile application as a dictionary. I have a text file that store all the words in Russian with a translation in English. I need to make a search from this file, when to enter words and need to show the translation. I am writing code on Ionic 3. I have error: fs.readFile is not a function.(In 'fs.readFile('dic.txt','utf8')','fs.readFile' is undefined)

  • Welcome to Stack Overflow! Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to specific programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](https://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – WhatsThePoint Oct 12 '18 at 12:03
  • You can look at this:https://stackoverflow.com/questions/10058814/get-data-from-fs-readfile – I_Al-thamary Oct 13 '18 at 05:12

1 Answers1

1

You can read a json file

import { HttpClient } from '@angular/common/http'; 
import { Observable } from 'rxjs/Observable';

   constructor(private http: HttpClient) {
        public getTranslation(): Observable<any> {
            return this.http.get("./assets/translation.json")
        }
   }
Ntwobike
  • 2,406
  • 1
  • 21
  • 27