Access external files in Angular 2

1

I have created a project in Angular 2 within a JavaScript project.

I need to use data and objects, within this Angular application, that are in external files and can not be moved from there.

By making use of the CLI ng serve command and creating my App in http://localhost:4200/ the files, obviously it does not collect them, although doing a ng build --prod of the application this is solved, but then I must be executing this command constantly for each change to see the actual results with the external files.

Is there a solution to make use of these files with their data and objects during the testing phase, which would be equivalent to http://localhost:4200/ ?

    
asked by Crisiiii 23.02.2017 в 11:47
source

1 answer

1

You do not collect the files from the AngularCLI because you have to configure it to do so. The procedure is simple.

In your angular-cli.json file, change or add this:

...
"apps": [{
            "root": "src", // carpeta root
            "outDir": "dist",
            "assets": [
                "assets",
                "miarchivo.json",
                "micarpeta",
                "test/datos.js",
            ],
            ...

Those files must be in the root folder.

    
answered by 01.03.2017 / 10:56
source