Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I am working on Django mult-tenancy project using Angular as client.

Prasit Gebsaap soap

💭
I am working on Django mult-tenancy project using Angular as client.
View GitHub Profile
@soap
soap / ObjectToFormData.ts
Created Apr 18, 2019
Convert object to FormData
View ObjectToFormData.ts
function createFormData(object: Object, form?: FormData, namespace?: string): FormData {
const formData = form || new FormData();
for (let property in object) {
if (!object.hasOwnProperty(property) || !object[property]) {
continue;
}
const formKey = namespace ? `${namespace}[${property}]` : property;
if (object[property] instanceof Date) {
formData.append(formKey, object[property].toISOString());
} else if (typeof object[property] === 'object' && !(object[property] instanceof File)) {
@soap
soap / object-to-form-data.js
Created Apr 18, 2019 — forked from ghinda/object-to-form-data.js
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
View object-to-form-data.js
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@soap
soap / api.module.ts
Created Mar 23, 2019 — forked from Toilal/api.module.ts
@auth0/angular2-jwt Authorization Service and HttpInterceptor supporting JWT Refresh Token (Angular 4.3+ & 5+)
View api.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { JWT_OPTIONS, JwtInterceptor, JwtModule } from '@auth0/angular-jwt';
import { AuthorizationService } from './authorization.service';
import { environment } from '../../environments/environment';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { RefreshTokenInterceptor } from './refresh-token-interceptor';
function jwtOptionsFactory (authorizationService: AuthorizationService) {
return {