I’m trying to read file from asset. My code is:
import { HttpClient, HttpParams, HttpHeaders, HttpRequest } from "@angular/common/http";
.
.
assetURL: string = "../assets/";
androidAssetURL: string = "'../www/assets/";
.
.
public readAssetFile(fileName: string) {
var url = this.assetURL + fileName;
if (this.platform.is("cordova") && this.platform.is("android")) {
url = this.androidAssetURL + fileName;
}
this.log("reading data file location:" + url);
return this.http
.get(url, { responseType: "text" })
.first()
.toPromise();
}
the location works for web
reading data file location:…/assets/data/about
but on device I get the location
reading data file location:'…/www/assets/data/about
but the real content isn’t read instead, get the HTML below as content
data file:<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<script data-ionic="inject">
(function(w){var i=w.Ionic=w.Ionic||{};i.version='3.9.2';i.angular='5.2.11';i.staticDir='build/';})(window);
</script>
<meta charset="UTF-8">
<title>Ionic App</title>
<meta name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<met
.
.
.