Posts

Showing posts with the label Angular2 Http

Angular 2 Http.post() Is Not Sending The Request

Answer : Since the post method of the Http class returns an observable you need to subscribe it to execute its initialization processing. Observables are lazy. You should have a look at this video for more details: https://egghead.io/lessons/rxjs-rxjs-observables-vs-promises You must subscribe to the returned observable if you want the call to execute. See also the Http documentation. Always subscribe! An HttpClient method does not begin its HTTP request until you call subscribe() on the observable returned by that method. This is true for all HttpClient methods . The AsyncPipe subscribes (and unsubscribes) for you automatically. All observables returned from HttpClient methods are cold by design. Execution of the HTTP request is deferred , allowing you to extend the observable with additional operations such as tap and catchError before anything actually happens. Calling subscribe(...) triggers execution of the observable and causes HttpClient to compose an...

Cannot Find Module './in-memory-data-service' In Tour Of Heroes For Angular2

Answer : ng generate service InMemoryData --module=app Will create the src/app/in-memory-data.service.ts file. Then add the code listed in the tutorial and it will work. AFAIK they don't even imply that in the tutorial so don't feel bad. In fact what they say is The forRoot() configuration method takes an InMemoryDataService class that primes the in-memory database. The Tour of Heroes sample creates such a class src/app/in-memory-data.service.ts Which is gibberish and wrong. My projects created using current CLI Tools, and I installed this: npm install angular-in-memory-web-api --save It works for me. Just make sure all your bases are covered In your package.json , should match the one on this page. "angular-in-memory-web-api": "~0.1.1", Also, your systemjs.config file looks good too! In your app.module.ts , make sure that your in-memory-data-service import matches your file because in their example they have in-memory-data.service ...