marioosh.net

mini blog / notes

@PreAuthorize and SpEL params

If @PreAuthorize is used on interface, parameter name (id) in SpEL must match parameter name in implementation (not required on interface – fileId). @Transactional public interface FileService {   @PreAuthorize("@securityService.canAccessFile(#id)") File getFile(Long fileId); }   /** * GOOD */ @Service public class FileServiceImpl implements FileService {   @Override public File getFile(Long id) { /* … Read more about @PreAuthorize and SpEL params[…]

Required @Input

selector: ‘app-test[id]‘ Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }Component({ selector: ‘app-test[id]’ // id is required now }); export class TestComponent { @Input() id:number; }

rx.js – chain requests when need response from BOTH

On the end i need response from BOTH requests, but need chain them, because second request need something from first response. import { switchMap, map } from ‘rxjs/operators’;   this.restService.getFile(id) .pipe( switchMap((file:File) => this.restService.renderMd(file.markdown_id) .pipe(map((markdown:any) => { return { file:file, markdow: markdown }; })) ) ).subscribe((result:any) => { // I have results for two requests Read more about rx.js – chain requests when need response from BOTH[…]

@HostBinding example

import { Component, HostBinding, Input, OnInit } from ‘@angular/core’;   @Component({ selector: ‘app-host’, template: `<p>host works!</p>`, styles: [`:host(.someClass){ color: red; }`] }) export class HostComponent implements OnInit {   @Input(’idVal’) @HostBinding(’id’) id:string = ‘defaultId’; @Input() @HostBinding(’class.someClass’) withClass:boolean = true;   constructor() { }   ngOnInit(): void { }   }import { Component, HostBinding, Input, OnInit Read more about @HostBinding example[…]

Return local json file from HttpClient

Steps add file.json to src/assets directory use this.http.get('assets/file.json'); in HttpClient import { Injectable } from ‘@angular/core’; import { HttpClient } from ‘@angular/common/http’; @Injectable({ providedIn: ‘root’ }) export class ApiService { constructor(private http: HttpClient) { } getLocalJson() { return this.http.get(‘assets/file.json’); } }

updateValueAndValidity();

updateValueAndValidity() works for control, but NOT for children ! form:FormGroup; constructor(private fb:FormBuilder) { }   initForm() { this.form = this.fb.group({ ‘files’:[”, [this.fv.bind(this)]] }); }   /** * my validator */ fv(fc:AbstractControl) { console.log(’validate’, fc); // … }   /** * func that need to revalidate ‘files’ field */ someFunc() { // … this.form.updateValueAndValidity(); // NOT Read more about updateValueAndValidity();[…]

Change commit date

$ git rebase -i HEAD~3   In editor mark commit that need change as ‘edit’ (the second commit in example below)   pick 64b0966 commit message 1… edit 07f540b commit message 2… pick a2b69e4 commit message 3…   # Rebase 50d9975..a2b69e4 onto 50d9975 (3 command(s)) # # Commands: # p, pick = use commit # Read more about Change commit date[…]

Posted in git

rx.js – chain requests

I don’t need result from first request, but need their response for second request (`switchMap` will be working, too) import { mergeMap } from ‘rxjs/operators’;   this.http.get(’/request1’).pipe( mergeMap((resp1:any) => this.http.post(’/request2′, resp1) ) ).subscribe(res => { // I have result from second request only console.log(res); });import { mergeMap } from ‘rxjs/operators’; this.http.get(‘/request1’).pipe( mergeMap((resp1:any) => this.http.post(‘/request2’, resp1) Read more about rx.js – chain requests[…]