Error: Uncleanness (in promise): Response with status: 404 Not found for url when upgrading to Angular-CLI + Angular 4

I updated my project, and everything was fine Angular 2 and now 4. Now I have resulted Angular-CLI 1.0.0

and it will not find the json file for primeNG.

 constructor(private http: Http) {}

    getFiles() {
        return this.http.get('mock_data/data.json')
            .toPromise()
            .then(res => <TreeNode[]> res.json().data)
            .then(data => { return data; });
    }

      

Throws an error and I tried adding ./

to copy the folder path to double check.

In my index.html

file I have <base href="/">

and the directory is undersrc

Mistake:

core.es5.js:1084 ERROR Error: Uncaught (in promise): Response with status: 404 Not Found for URL: http://localhost:4200/mock_data/data.json

      

enter image description here

+3


source to share


1 answer


Try moving mock_data

to a folder assets

and then refresh the url with 'assets/mock_data/data.json'

.


Suggested edit:



Another way, just add "mock-data"

to the file .angular-cli.json

:

"assets": [
            "assets",
            "favicon.ico",
            "mock-data"
        ]

      

+1


source







All Articles