Is it possible to generate services for Angular2 from Loopback?

Here is the documentation for the AngularJS JavaScript SDK

This example is great for Angular. You can create an Angular client library with the command

$ lb-ng ../server/server.js js/lb-services.js 

Is there an equally easy way to use Angular2 with Loopback?

EDIT

What I have found on this subject at the moment.

  • Issue in loopback-sdk- angular Github repository with discussion.
  • Implementation example: BaseResource and Model based on BaseResource.
  • And one more way - using upgrade from Angular to Angular2 before the official implementation of the Loopback Angular 2 SDK.
  • I made an alpha version of the code generator for Angular 2 in fork loopback-sdk-angular .

EDIT

  1. Loopback-sdk-builder ( comment )
+7
javascript angular loopbackjs
source share
1 answer

At this point, you can use the fork of the loopback-sdk-angular and loopback-sdk-angular-cli packages.

package.json:

 "devDependencies": { //... "loopback-sdk-angular": "github:qeti/loopback-sdk-angular#188-angular2-support", "loopback-sdk-angular-cli": "github:qeti/loopback-sdk-angular-cli#37-angular2-support" } 

Create Client Code (TypeScript):

 ./node_modules/.bin/lb-ng ./server/server.js ./client/src/app/lb-services.ts -l angular2 

Usage example:

 import {Component,Injectable} from 'angular2/core'; import {UserApi as UserService} from './lb-services'; import {HTTP_PROVIDERS} from 'angular2/http'; @Component({ selector: 'my-app', providers: [UserService,HTTP_PROVIDERS], template: 'some template' }) @Injectable() export class AppComponent { private login: string; private password: string; constructor(protected user: UserService) {} onLogin() { let self = this; // Example 1 this.user.login({ username: self.login, password: self.password }) .subscribe(res => { // some actions on login this.getData(); }); } onLogout() { // Example 2 this.user.logout().subscribe(() => { // some actions on logout }); } public getData() { // Example 3 this.user.count().subscribe((response: any) => { let lastRow = response.count; let data = this.user // Example 4 .find({ offset: 0, limit: 100 }) .subscribe(function(response: any) { // Process response }); }); } } 
+13
source share

All Articles