****************Change Event *************
onChange(event: EventTarget) {
let formData = new FormData();
let eventObj: MSInputMethodContext = event;
let target: HTMLInputElement = eventObj.target;
let files: FileList = target.files;
this.file = files[0];
let formData = new FormData();
formData.append('FileDocument', this.file);
return this.http.post(`UrlPath`, formData)
.map((res: Response) => {
});
}
******************WEB API******************
[HttpPost]
public void GetImage()
{
var ImageData= System.Web.HttpContext.Current.Request.Files["FileDocument"];
ImageData.SaveAs(Path);
}
Showing posts with label Angular 2. Show all posts
Showing posts with label Angular 2. Show all posts
Monday, February 12, 2018
Input Only Number in Iput Type in Angular 2
Input Only Number in Input Type in Angular 2
-- Html Code here
First Create Directive.ts File and Put Code Inside
*************************onlynumber.directive.ts***************************
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
selector: '[OnlyNumber]'
})
export class OnlyNumber {
constructor(private el: ElementRef) { }
@Input() OnlyNumber: boolean;
@HostListener('keydown', ['$event']) onKeyDown(event) {
let e = event;
if (e.which == 13) {
e.preventDefault();
var $next = $('[tabIndex=' + (+ parseInt(e.target['tabIndex']) + 1) + ']');
if (!$next.length) {
$next = $('[tabIndex=1]');
}
$next.focus();
}
else if (this.OnlyNumber) {
if ([46, 8, 9, 27, 13, 190].indexOf(e.keyCode) !== -1 ||
(e.keyCode == 65 && e.ctrlKey === true) ||
(e.keyCode == 67 && e.ctrlKey === true) ||
(e.keyCode == 88 && e.ctrlKey === true) ||
(e.keyCode >= 35 && e.keyCode <= 39)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
}
}
}
Subscribe to:
Posts (Atom)