How to run a onclick javascript function when use Angular ngNoForm

<form target=”_blank”id=”pdf_form”action=”/backend/pdf” ngNoForm method=”post” class=”pdf-request”> ….. <button type=”submit”class=”btn btn-info btn-sm mr-2 ” (click)=”printPdfNow(‘Yes’)”><i class=”fa fa-print mr-1 ml-2″ aria-hidden=”true”></i>Print Now</button> <input type=”hidden”name=”print_now”value=”No” /> …. </form> js function in Angular xxx.ts: printPdfNow(print_or_not: string) { let f = <HTMLFormElement>document.getElementById(‘pdf_form’); console.log(f.print_now.value); if (print_or_not == ‘Yes’) { if (confirm(‘Are your sure to print the harvest slip(s) automatically?’)) { f.print_now.value = …

How to fix Malformed UTF-8 characters, possibly incorrectly encoded while upload CSV file

Actually, it not related to upload csv file, but there might be some non-utf8 characters when edit csv file which cause this error Malformed UTF-8 characters, possibly incorrectly encoded $importFiles = SomeModel::updateOrCreate( [ ‘someid’ => utf8_encode($item[‘someid’]) ], [ ‘name’ => $item[‘THE NAME’], ‘date’ => $item[‘THE Date’], or we can use: mb_convert_encoding($item[‘EID’], ‘UTF-8’, ‘UTF-8’);

Why the php generated PDF file in different font and size? How to display image for php dompdf?

First, only few standard font supported: The PDF specification requires that PDF readers support a core set of fonts. These fonts are as follows: Courier (Normal, Bold, Oblique, and BoldOblique variants) Helvetica (Normal, Bold, Oblique, and BoldOblique variants) Times (Normal, Bold, Oblique, and BoldOblique variants) Symbol ZapfDingbats Then, the html and body css style has …

How to pass value in Angular form using PUT method for update laravel api?

Laravel PUT method usually used for update, but can’t get data/value from upload file. How to pass value in Angular form using PUT method for update laravel api? html form: <form class=”w-75″ [formGroup]=”main_form” (ngSubmit)=”onSubmit()” enctype=”multipart/form-data”> <div class=”form-row”> <input class=”form-control-file” (change)=”fileChange($event)” type=”file” name=”avatar_file” formControlName=”avatar_file” placeholder=”Upload file”accept=”.png,.jpg,.jpeg,.gif” id=”avatar_file”> .ts: avatar_file: new FormControl(undefined),  //use undefined to avoid console …

How to set web user session login and csrf token after passport oauth api login in Angular

When post a passport oauth api login in Angular, set login api use web routes middleware. web.php: Route::post(‘/api/v1/login’, ‘API\[email protected]’); instead of use api.php: Route::post(‘login’, ‘[email protected]’); This will set a laravel_session in cookie, and you will only need use Angular http post request login once, no need to login from web form again. You can directly …

How to add/send Authorization Bearer access_token request header to get/retrieve user information

Here, we use Laravel Middleware changing header before passing to controller App\Http\Middleware\CheckAccessToken.php: namespace App\Http\Middleware; use Closure; class CheckAccessToken { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (isset($_COOKIE[‘access_token’])) { $request->headers->set(‘Authorization’, ‘Bearer ‘ . $_COOKIE[‘access_token’]); } //dd($request->headers); return …

How to set access token cookie while login via passport oauth2

protected function authenticated(Request $request, $user) { $username = $request->input(’email’); // if ( $request->username !== null ) { // $username = $request->input(‘username’); // } $password = $request->input(‘password’); $request->request->add([ ‘username’ => $username, ‘password’ => $password, ‘grant_type’ => ‘password’, ‘client_id’ => env(‘OAUTH2_CLIENT_ID’), ‘client_secret’ => env(‘OAUTH2_CLIENT_SECRET’), ‘scope’ => ‘*’ ]); $tokenRequest = Request::create( env(‘APP_URL’) . ‘/oauth/token’, ‘post’ ); $token_json …

How to remove “format on save” space before and after closing braces in VS Code

to prevent {key: ‘value’} being changed to { key: ‘value’ } when formatting, add below to user setting in your vs code: “editor.formatOnSave”: true, “editor.formatOnType”: true, “javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces”: false, “typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces”: false, to the VS Code settings, to be able to prevent {key: ‘value’} being changed to { key: ‘value’ } when formatting

How to get id parameter or route parts from Angular route path or url

ngOnInit() { //let last_route_part: string = this.route.snapshot.url[this.route.snapshot.url.length – 1].toString(); //console.log(‘url=’ + url + ‘, last_route_part=’ + last_route_part); this.route.url.subscribe((url_parts: UrlSegment[]) => { //console.log(‘url_parts=’ + url_parts + ” last_route_part=” + url_parts[url_parts.length – 1].toString()); this.last_route_part = url_parts[url_parts.length – 1].toString(); //console.log(‘last_route_part1=’ + this.last_route_part); }); this.route.params.subscribe((params: Params) => { this.edit_record_id = Number(params[‘id’]); }); //console.log(‘last_route_part2=’ + this.last_route_part); if (this.last_route_part == ‘create’) …