I have an app that can upload images. Everything is working fine, I;m not having issues with the upload itself...
But I have issues because as soon as I upload the image and storage in the server, the angular-clie reload the page.
At first, I was uploading the images to /src/assets
Then I relized that angular-clie is refreshing the page, because it detect some new content on the folder it's listeing. So I change that and now the images are being uploading to /resources (outside src folder) so now angular-clie is not refreshing the page... But they are not vissible for the web app as they are not in the "public folder".
So my question... Where should I upload the images without fire a page reload? / Or how I add an exception to angular-cli?
As backend I'm using Java with Spring, and that part is working fine.
My angular2 structure is:
/
/resources
/src
/src/app
/src/assets
/dist
etc...
My angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ng2angle"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"app/core/preloader/preloader.scss",
"styles.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"app/core/preloader/preloader.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"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
COnsole Log when uploading:
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
{success: true, code: null, data: {…}}
[WDS] App updated. Recompiling...
[WDS] App updated. Reloading...
Function to sent file to backend:
save(event) {
let fileList: FileList = event;
if(fileList.length > 0) {
let file: File = fileList[0];
let formData:FormData = new FormData();
formData.append('file', file, file.name);
let headers = new Headers();
/** No need to include Content-Type in Angular 4 */
let options = new RequestOptions(this.createAuthHeadersForUpload());
return this._http.post(`${this.baseUrl + '/save'}`, formData, options)
.map((response: Response) => <JsonResponse>response.json())
.do(function (response) {
console.log(response);
})
.catch(this.handleError);
}
else
return null;
}
See Question&Answers more detail:
os