marioosh.net

mini blog / notes

*ngTemplateOutlet

<ng-template #toolbar> lorem ipsum… </ng-template>   <!– put my template here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container>   <!– and here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container>   <!– and here, too 😉 –> <ng-container *ngTemplateOutlet="toolbar"></ng-container><ng-template #toolbar> lorem ipsum… </ng-template> <!– put my template here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container> <!– and here –> <ng-container *ngTemplateOutlet="toolbar"></ng-container> <!– and here, too 😉 –> <ng-container Read more about *ngTemplateOutlet[…]

array to map with reduce()

let months = [ {month: 1, data1: "test1", data2: "test2"}, {month: 2, data1: "test1", data2: "test2"}, {month: 3, data1: "test1", data2: "test2"} ];   let monthsAsMap = months.reduce((map, obj) => { map[obj.month] = obj; return map; }, {});   console.log(monthsAsMap); console.log(monthsAsMap[’2’]);let months = [ {month: 1, data1: "test1", data2: "test2"}, {month: 2, data1: "test1", data2: Read more about array to map with reduce()[…]

@PreAuthorize with use Spring Expression Language (SpEL) and service method call

public interface EventRepository extends JpaRepository<Event, Long> {   @PreAuthorize("@securityService.canSave(#event,principal)") Event save(@Param("event") Event event);   @PreAuthorize("@securityService.canSave2(#event)") Event save2(@Param("event") Event event); }   @Service("securityService") public class SecurityService {   public boolean canSave(Event event, UserDetails principal) { // some logic here }   public boolean canSave2(Event event) {   // get principal from Security Context Object principal = Read more about @PreAuthorize with use Spring Expression Language (SpEL) and service method call[…]

AsyncPipe example

@Component({ … }) export class TestingComponent implements OnInit { units: any; constructor(private restService:RestService) { } ngOnInit() { this.units = this.restService.getUnits(); } }@Component({ … }) export class TestingComponent implements OnInit { units: any; constructor(private restService:RestService) { } ngOnInit() { this.units = this.restService.getUnits(); } } Template <ng-template #loading>Loading…</ng-template> <div *ngIf="units|async as units; else loading"> <span *ngFor="let unit Read more about AsyncPipe example[…]

JSON -> List

import org.springframework.core.io.Resource; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper;   …   @Value("classpath:/strings.json") private Resource jsonFile;   @Autowired private ObjectMapper mapper;   …   List<String> listOfStrings = Arrays.asList( mapper.readValue(jsonFile.getInputStream(), String[].class) );import org.springframework.core.io.Resource; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; … @Value("classpath:/strings.json") private Resource jsonFile; @Autowired private ObjectMapper mapper; … List<String> listOfStrings = Arrays.asList( mapper.readValue(jsonFile.getInputStream(), String[].class) );