我遇到了Angular 5的问题。作为recovder的模块 csv 我使用的是Papa.parse版本4模块。我正在使用Chrome进行调试。
我有下一个目录结构:
资产/数据中的每个目录都有一个文件: data.csv 。
Papa.parse代码是:
import { Injectable, NgModule } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from "rxjs/Observable";
import { Http, Response } from '@angular/http';
import { PapaParseModule } from 'ngx-papaparse';
import { PapaParseService } from 'ngx-papaparse';
import { Capcaleres } from "../assets/models/Capcaleres.Model";
@Injectable()
export class DataService {
private csvData: any[] = [];
private Papa: any = null;
constructor(private http: Http, private papa: PapaParseService) {
this.Papa = papa;
}
public cargarFitxer(obj: any): any
{
debugger;
// preparo la url
var url: string = "../../assets/assets/{0}/{1}/data.csv";
var clase: any = obj;
var nomClase: string = clase.constructor.name.toLowerCase();
var manteniments: string[] = [
"capcaleres",
"idiomes",
"llenguatgesprogramacio",
"nivells",
"posicions",
"tipusempresa"
];
var tipus = (manteniments.find(x => x === nomClase)) ? "manteniments" : "llogica";
url = url.replace("{0}", tipus);
url = url.replace("{1}", nomClase);
debugger;
// recullo la informació.
this.Papa.parse(url, {
worker: false,
download: true,
complete: function () {
console.log("All done!");
debugger;
}
});
}
}
其中data.service.ts位于app目录级别。
我的angular-cli.json文件是:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "admin-angular"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico",
"data.csv"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css",
"../src/assets/scss/style.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/pace-js/pace.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
我没有编译错误:
在chrome中,错误是找不到404文件
有什么问题?我不知道该怎样做Angular可以识别我的csv和Papa.parse可以工作。
安全级别可能是IIS等目录吗?
我单独执行的url文件,并且可以毫无问题地识别url。我需要添加什么?
最好的问候
答案 0 :(得分:0)
Thx Simon K。
两只眼睛比一个数据好得多......软件错误