Skip to content

Instantly share code, notes, and snippets.

@joshcaplin
joshcaplin / Angular-2-example-with-Http-service.md
Last active April 22, 2016 02:52
Angular2, Angular 2, AngularJS2, AngularJS 2, example with HTTP GET, Beta 15, TypeScript

Simple Angular 2 example with service for HTTP call

  • These are the core files I used for my Angular 2 test, it's based on the Beta 15 release, so keep that in mind if you're using a different version.
  • If you're just starting out, be careful with basing your code on outdated information - the syntax has changed a lot through the Alpha and Beta versions.
  • I set up the http GET to call a server side ASP .NET MVC action, which calls the SWAPI (Star Wars API) and returns the data back to the browser. You may need to adjust this part of it, if you want to handle the call differently, get the data back in a different format, etc.
  • This is setup to use the transpiled Javascript code (see index.html where it specifies default extension of 'js'. As a shortcut you can use your raw TypeScript code, but this will significantly slow down your page because you need to load the huge typescript.js library and it needs to transpile the code on-the-fly.
  • I added this into an existing