angular - Error: XHR error (404 Not Found) loading angular2/http -
i using angular-cli angular2 application. whenever try load angular2/http in components/services no error shows in cli terminal in browser's console shows -
get http://localhost:4200/angular2/http 404 (not found)
unhandled promise rejection: error: xhr error (404 not found) loading http://localhost:4200/angular2/http @ xmlhttprequest.desc.set.wrapfn [as _onreadystatechange] (http://localhost:4200/vendor/zone.js/dist/zone.js:769:30) @ zonedelegate.invoketask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38) @ zone.runtask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48) @ xmlhttprequest.zonetask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:423:34) error loading http://localhost:4200/angular2/http "angular2/http" http://localhost:4200/app/js-tree.component.js ; zone: ; task: promise.then ; value: error: error: xhr error (404 not found) loading http://localhost:4200/angular2/http @ xmlhttprequest.desc.set.wrapfn [as _onreadystatechange] (http://localhost:4200/vendor/zone.js/dist/zone.js:769:30) @ zonedelegate.invoketask (http://localhost:4200/vendor/zone.js/dist/zone.js:356:38) @ zone.runtask (http://localhost:4200/vendor/zone.js/dist/zone.js:256:48) @ xmlhttprequest.zonetask.invoke (http://localhost:4200/vendor/zone.js/dist/zone.js:423:34) error loading http://localhost:4200/angular2/http "angular2/http" http://localhost:4200/app/js-tree.component.js
my angular-cli version 0.0.39
node : 4.2.2
here goes system-config.ts
const map: = { }; /** user packages configuration. */ const packages: = { }; const barrels: string[] = [ // angular specific barrels. '@angular/core', '@angular/common', '@angular/compiler', '@angular/http', '@angular/router', '@angular/platform-browser', '@angular/platform-browser-dynamic', // thirdparty barrels. 'rxjs', // app specific barrels. 'app', 'app/shared', 'app/tree', 'app/tree/item', /** @cli-barrel */ ]; const clisystemconfigpackages: = {}; barrels.foreach((barrelname: string) => { clisystemconfigpackages[barrelname] = { main: 'index' }; }); /** type declaration ambient system. */ declare var system: any; // apply cli systemjs configuration. system.config({ map: { '@angular': 'vendor/@angular', 'rxjs': 'vendor/rxjs', 'main': 'main.js' }, packages: clisystemconfigpackages }); // apply user's configuration. system.config({ map, packages });
and package.json
{ "name": "pankha", "version": "0.0.0", "license": "mit", "angular-cli": {}, "scripts": { "start": "ng server", "postinstall": "typings install", "lint": "tslint \"src/**/*.ts\"", "format": "clang-format -i -style=file --glob=src/**/*.ts", "pree2e": "webdriver-manager update", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/common": "2.0.0-rc.1", "@angular/compiler": "2.0.0-rc.1", "@angular/core": "2.0.0-rc.1", "@angular/platform-browser": "2.0.0-rc.1", "@angular/platform-browser-dynamic": "2.0.0-rc.1", "@angular/router": "2.0.0-rc.1", "es6-shim": "^0.35.0", "reflect-metadata": "0.1.3", "rxjs": "5.0.0-beta.6", "systemjs": "0.19.26", "zone.js": "^0.6.12" }, "devdependencies": { "angular-cli": "0.0.*", "clang-format": "^1.0.35", "codelyzer": "0.0.14", "ember-cli-inject-live-reload": "^1.4.0", "jasmine-core": "^2.4.1", "jasmine-spec-reporter": "^2.4.0", "karma": "^0.13.15", "karma-chrome-launcher": "^0.2.3", "karma-jasmine": "^0.3.8", "protractor": "^3.3.0", "ts-node": "^0.5.5", "tslint": "^3.6.0", "typescript": "^1.8.10", "typings": "^0.8.1" } }
and index.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>pankha</title> <base href="/"> {{content-for 'head'}} <link rel="icon" type="image/x-icon" href="favicon.ico"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- service worker support disabled default. install worker script , uncomment enable. enable service workers in production. <script type="text/javascript"> if ('serviceworker' in navigator) { navigator.serviceworker.register('/worker.js').catch(function(err) { console.log('error installing service worker: ', err); }); } </script> --> </head> <body> <pankha-app>loading...</pankha-app> <script src="vendor/es6-shim/es6-shim.js"></script> <script src="vendor/reflect-metadata/reflect.js"></script> <script src="vendor/systemjs/dist/system.src.js"></script> <script src="vendor/zone.js/dist/zone.js"></script> <!-- <script src="node_modules/angular2/bundles/http.dev.js"></script> --> <script> system.import('system-config.js').then(function () { system.import('main'); }).catch(console.error.bind(console)); </script> </body> </html>
i think forgot include http.dev.js
file in main html file:
<script src="node_modules/angular2/bundles/http.dev.js"></script>
note applies beta versions (not rc ones) since use angular2/http
module, guess use beta version.
Comments
Post a Comment