Git Product home page Git Product logo

angular2-django's Introduction

angular-django

angular-django is Django Rest Framework API & Material components for Angular 5+. Use the Django API in an easy way and as objects and build grids, lists and forms in an easy and reusable way.

API Usage

Some examples of the API.

List items from API

export class SnippetListComponent implements OnInit {
        snippets: Snippet[];
    
        constructor(
            private api: SnippetApi,
        )
        
        ngOnInit() {
            // Get first page from API filtered by language = Python and ordered
            // by -created.
            this.api.orderBy('-created').filter({'language': 'python'})
                    .page(1).all().subscribe((snippets: Snippet[]) => {
                this.snippets = snippets;
            });
        }
}

Get and item and edit it.

export class SnippetEditComponent implements OnInit {
        snippet: Snippet;
        highlightedCode: string;
        localDateTime: string;
        ownerFullName: string;
    
        constructor(
            private api: SnippetApi,
        )
        
        ngOnInit() {
            // Get first page from API filtered by language = Python and ordered
            // by -created.
            this.api.get(12).subscribe((snippet: Snippet) => {
                // Execute a method on Snippet
                this.highlightedCode = snippet.getHighlightedCode();
                // Execute a method on User serializer
                this.ownerFullName = snippet.owner.getFullName();
                // created is converted to Date
                this.localDateTime = snippet.created.toLocaleDateString();
                // Change snippet title (unsaved)
                snippet.title = 'New snippet title'
                // Save changes
                snippet.save().subscribe();
            });
        }
}

Serializer and API

export class Snippet extends SerializerService {

    @Field() title: string;
    @Field() owner: User;  // User is also a serializer
    @Field() created: Date;
    @Field() code: string;
    @Field() language: string;
    
    getHighlightedCode() {
        // Method on Serializer
        return '...'
    }
}


@Injectable({
  providedIn: 'root'
})
export class SnippetApi extends ApiService {

    url = '/api/snippets/';
    serializer = Snippet;

    constructor(http: HttpClient) {
        super(http);
    }
}

Material Components

django-table

Features

  • Sort columns
  • Pagination
  • Change page size
  • Parameters in the url

django-form

Features

  • Create, update and patch methods
  • Nested models (OneToOne & ManyToOne; OneToMany & ManyToMany unsupported)
  • Featured widgets:
    • Input (text, number, etc. types)
    • Textarea
    • Select (django choices)
    • Datetime
    • Checkbox
    • django-search-input (Search on Django via API and select instance)
  • Input server validation

Installation

To install this library, run:

$ npm install angular-django --save

Consuming your library

Once you have published your library to npm, you can import your library in any Angular application by running:

$ npm install angular-django

and then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { SampleModule } from 'angular-django';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Specify your library as an import
    LibraryModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once your library is imported, you can use its components, directives and pipes in your Angular application:

<!-- You can now use your library component in app.component.html -->
<h1>
  {{title}}
</h1>
<sampleComponent></sampleComponent>

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © nekmo

angular2-django's People

Contributors

nekmo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

angstormnet

angular2-django's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.