Skip to content

Instantly share code, notes, and snippets.

@hassanKhademi
Last active February 13, 2020 13:05
Show Gist options
  • Save hassanKhademi/15db55b871f8b09c847e8773ab59270d to your computer and use it in GitHub Desktop.
Save hassanKhademi/15db55b871f8b09c847e8773ab59270d to your computer and use it in GitHub Desktop.
angularTemplate
//=========================================================================================== use modal
bsModalPending: BsModalRef;
const initialState = {
InputNameOnComponent://ورودی کمپوننت
};
const configModal = {
class: "modal-sm"
};
constructor(private modalService: BsModalService) {}
this.bsModalPending = this.modalService.show(this.changeUserCeatorTemplate, { initialState, ...configModal });
this.modalService.onHidden.subscribe(res => {
// do anything
});
//=========================================================================================== add header to httpClient in angular
import { HttpClient, HttpHeaders } from '@angular/common/http';
...
constructor(private http: HttpClient){}
...
sendRequest(){
const headers = new HttpHeaders({ "Content-Type": "application/json"});
return this.http.post(url, param, { headers: headers });
}
//=========================================================================================== router in angular
// in html file
// without param
<a [routerLink]="['/hero']">link</a>
// by param
<a [routerLink]="['/hero', hero.id]">link</a>
// by queryparams
<a [routerLink]="['/hero/bob']" [queryParams]="{debug: true}" fragment="education">link</a>
------------------------------------------------------------------------------------------- download file
downloadfile(model: mod.IFileSave[]): void {
const req = [];
model.forEach((d: mod.IFileSave) => {
req.push(this.http.get(d.url, { responseType: 'blob' }));
});
forkJoin(req).subscribe((res: any[]) => {
res.forEach((blob, i) => {
if (model[i].name) {
importedSaveAs(blob, model[i].name);
} else {
importedSaveAs(blob);
}
})
})
}
//tooltip class
.tooltip-test{
position:relative;
display:inline-block;
}
.tooltip-test .tooltiptext-test{
visibility:hidden;
width:80px;
background-color:black;
color:#fff;
text-align:center;
font-size:12px;
opacity:0.9;
border-radius:6px;
padding:5px 0;
position:absolute;
z-index:10;}
.tooltip-test:hover .tooltiptext-test{
visibility:visible;
}
//------------------------------------------------------ animation
<div class="selector-div"></div>
@keyframes animation-name {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.selector-div {
background-color:white;
height:30px;
width:30px;
border-radius:50%;
border:10px solid white;
border-right:10px solid black;
animation: animation-name 1s infinite linear;//linear حرکت به صورت روان
}
import * as moment from "jalali-moment";
date;// model
shamsi = moment.form(this.date,'fa').locale('fa').format('YYYY-MM-DD HH:mm:ss')//HH 24,hh 12
enDate = moment.from(this.date,'fa').format('YYYY-MM-DD HH-mm-ss')
//-------------------------------------------- for bind to model
this.date = moment('YYYY-MM-DD HH:mm:ss');
//-----------------------------------------in html
<dp-date-picker dir="rtl"
[(ngModel)]="date"
[config]="dpConfig"
mode="daytime"
theme="dp-material"
(onChange)="changeDate()"
placeholder="تا تاریخ">
</dp-date-picker>
--------------------------------------------------------------------// decode base64 javascript => from mozilla site
function b64DecodeUnicode(str) {
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
b64DecodeUnicode('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode"
b64DecodeUnicode('Cg=='); // "\n"
--------------------------------------------------------------------// decode base64 javascript => from mozilla site
********************************************************************//
$http.post('/fetchBlobURL',{myParams}, {responseType: 'arraybuffer'})
.success(function (data) {
var file = new Blob([data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment