Print document from cross-origin iframe

When you need to show content from some other site, such as Google Docs, you can easily embed it inside an iframe. Google Docs even generates it for you. But what if you need to print that document via some button click? You can not do that, because the cross-origin policy does not allow it. You have basically two options. A) Create some proxy function on your server. But that is only available when you actually have a server and not just some hosted WordPress. B) Create proxy iframe, which you are actually allowed to print, because there is no cross-origin involved. Then …

Continue Reading

Workaround for ExpressionChangedAfterItHasBeenCheckedError in async pipe

Imagine that you have this piece of code, where userInfo$ is Observable and it value is not yet emitted. <app-change-email [currentEmail]=”(userInfo$ | async).user.email”></app-change-email> The code works, but it will report error ExpressionChangedAfterItHasBeenCheckedError to the console (only in dev mode). That is because the component has received the value, but the value has changed later. Angular does not like it. I googled for solutions, but could not use them, or it would be too complicated in given setup. Workaround is easy <ng-template #loading> <div id=”loading”></div> </ng-template> <ng-container *ngIf=”userInfo$ | async; let userInfoState; else loading”> <app-change-email [currentEmail]=”userInfoState.user.email”></app-change-email> </ng-container>

Continue Reading

Angular custom event bubbling

Custom events in Angular by default do not bubble up. It is because they are not really events, they are based on EventEmitter, which is similar to pub/sub mechanism. You can read lengthy discussion about it on Angular’s Github. Unfortunately the examples provided by Angular team often mention $event as named parameter in the event listener, which only adds to the confusion. There are valid use cases when you really need the custom events to bubble up. Luckily, you can still create DOM-native custom events, and they will bubble up as expected. import { Component, OnInit, Input, ElementRef, Renderer } from …

Continue Reading

Node_modules versus Docker

I’ve encountered strange error lately. Whenever I tried  to run npm install in my project’s folder, it failed. The error says something about not being able to unlink folder. The interesting think was that it only happened under certain circumstances. The reason for this was the when I started docker compose up to run my project in Docker, it created some lock on the node_modules folder. And shutting down the container or even the whole Docker did not help. The lock stayed there. The only way to workaround this (at least which I am aware of) is to restart the …

Continue Reading