Skip to content

kaiu-lab/ng-serializer

Repository files navigation

ng serializer

Build Status codecov npm version devDependency Status GitHub issues GitHub stars GitHub license

Table of contents

About

Angular wrapper for @kaiu/serializer library

Installation

Install through npm:

npm install --save @kaiu/ng-serializer @kaiu/serializer

Then include in your apps module:

import { NgModule } from '@angular/core';
import { NgSerializerModule } from 'ng-serializer';

@NgModule({
  imports: [
    NgSerializerModule.forRoot()
  ]
})
export class MyModule {}

Finally use in one of your apps components:

import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { Foo } from './models/foo';
import { NgSerializerService } from '@kaiu/ng-serializer';

@Component({
  template: 'foo'
})
export class MyComponent implements OnInit {
    constructor(private http:Http, private serializerService:NgSerializerService){}
    
    ngOnInit():void{
        let data = this.http.get('https://foo.org/bar').map(response => {
           return this.serializerService.deserialize<Foo>(response.json(), Foo);
        });
        data.subscribe(fooModel => {
           fooModel.baz();//This will work ! 
        });
    }    
}

The full documentation of the serializer can be found on @kaiu/serializer's website.

Usage without a module bundler

<script src="node_modules/ng-serializer/bundles/ng-serializer.umd.js"></script>
<script>
    // everything is exported ngSerializer namespace
</script>

Development

Prepare your environment

  • Install Node.js and NPM
  • Install local dev dependencies: yarn install while current directory is this repo

Testing

Run yarn test to run tests once or yarn test:watch to continually run tests.

Release

  • Bump the version in package.json (once the module hits 1.0 this will become automatic)
yarn release

License

MIT