{"id":2818,"date":"2016-09-16T09:47:26","date_gmt":"2016-09-16T09:47:26","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=2818"},"modified":"2016-09-16T09:47:26","modified_gmt":"2016-09-16T09:47:26","slug":"use-http-angular-2-via-angular-cli","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/javascript\/angular-2\/use-http-angular-2-via-angular-cli\/","title":{"rendered":"How to use http in Angular 2 via angular-cli?"},"content":{"rendered":"<p>I initially tested and wrote a <a href=\"http:\/\/tutorials.pluralsight.com\/front-end-javascript\/getting-started-with-angular-2-by-building-a-giphy-search-application\">tutorial for Pluralsight<\/a> by using the <a href=\"https:\/\/cli.angular.io\/\">angular-cli<\/a> version <code>1.0.0-beta.9<\/code>.<\/p>\n<p>However, I&#8217;ve tried today with the <a href=\"https:\/\/github.com\/angular\/angular-cli\">latest version<\/a> and for the life of me I couldn&#8217;t figure out how to use HTTP to call some service.<\/p>\n<p>In the end, I figured what the issue was, so I&#8217;m putting it out here so it may be useful to someone else as well.<\/p>\n<p>So, when I installed angular-cli with <code>npm install -g angular-cli<\/code> I haven&#8217;t at first noticed this error:<br \/>\n<code>UNMET PEER DEPENDENCY webpack@2.1.0-beta.22<\/code><\/p>\n<p>What I ended up doing now was<\/p>\n<p><code>npm install webpack -g &amp;&amp; npm install webpack --save-dev<\/code><\/p>\n<p>and now I can normally include Http into my component like this:<\/p>\n<p><code>import { Http, Response } from '@angular\/http';<\/code><\/p>\n<p>and then use it within a class like this:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/Hitman666\/795939ab27acd16c5be1d0ba13586108.js\"><\/script><\/p>\n<p>Hope this helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I initially tested and wrote a tutorial for Pluralsight by using the angular-cli version 1.0.0-beta.9. However, I&#8217;ve tried today with the latest version and for the life of&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2819,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-2818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-2"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=2818"}],"version-history":[{"count":1,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2818\/revisions"}],"predecessor-version":[{"id":2820,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2818\/revisions\/2820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/2819"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=2818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=2818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=2818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}