Angular 2 Rails

Angular 2 HTTP Example

Following is a very simple Angular 2 HTTP GET example.

Since this is AngularOnRails.com, I have a Rails repo you can put behind the Angular code if you want. If you’re not a Rails person, 95% of what follows will still apply to you.

First, clone the Rails repo (optional) and grab tag v0.0.2.

In another window, run rails server from the project root.

If you’re not using my Rails repo, you can create a new Angular 2 project in the following way. (My Rails repo already has this.)

The rest of this example is the same whether you’re using Rails or not.

Spin up the Angular server by running

In order to be able to use Http at all, we’ll have to include HTTP_PROVIDERS in our application’s bootstrap. Modify src/main.ts to look like this.

Free Guide

Getting Started´╗┐ ´╗┐with Angular and Rails

Get an Angular/Rails app up and running in as little as 20 minutes

Now we’ll add a loadBooks() method (among other things) to AuthorWizardAppComponent.

We’ll invoke loadBooks() in our template and provide a place for the books to appear in the template.

Now, if you click the “Load books” button in the browser, a list of books should appear below the button.

About the author

Jason Swett

Add Comment

Click here to post a comment