angular2-trails-realtime An angular module for using the trails-realtime with primus in angular2 (@angular)
INDEX
Usage with angular-cli
Angular-cli is a great angular2 app starter for creating fancy angular stuff.
Here I will describe on how to install and use it:
1. Installing
install the package with the node package manager (npm)
npm install --save angular2-trails-realtime
2. Configure angular-cli
APP_ROOT/angular-cli-build.js
Here you may add a line of code, to add the package to your vendor files
var Angular2App = ; module { return defaults vendorNpmFiles: ... 'angular2-trails-realtime/dist/**/*.+(js|js.map)' ;};
APP_ROOT/src/system-config.ts
Here you have to register the module in the systemJS configuration and define the mapping location and the entry point.
/** Map relative paths to URLs. */;
/** User packages configuration. */
3. Using it
the import statement looks like this:
import { TrailsService } form 'angular2-trails-realtime';
You can provide the TrailsService in a Component by the provider array or (not recommended) by providing it in the bootstrap of your application.
Example in Component:
;; // and in a subcomponent of the provider component ;;
Example in bootstrap (not recommended):
...; bootstrapAppComponent, ; // and then again in a component ;;
working with it
You inject the service by the constructor where you want to use it.
constructorprivate _TrailsService:TrailsService
first you have to connect your service:
ngOnInit
you can pass in an Url or Options, where to connect to
ngOnInit
for more information, please visit sailsjs.org Documentation for SailsSocket Properties
this is handy, when you develop with angular-cli (localhost:4200) and the ng serve command and your sails app runs separately e.g on localhost:1337
The following methods are implemented in the TrailsService and will always return you an Observable:
- get(path,data):Observable
- post(path,data):Observable
- put(path,data):Observable
- delete(path,data):Observable
- request(options):Observable
- on(eventEntity):Observable
for more information, please visit sailsjs.org Documentation for SailsSocket Methods
You then have to subscribe to that Observable, to get the data.
EXAMPLE:
{{user.firstname}} {{user.lastname}}
;;
EXAMPLE with Async Pipe
or even better, you use the async pipe of angular, and just pass the Observable to it
{{user.firstname}} {{user.lastname}}
;;;