Skip to main content

Posts

Conflicting styles with multiple Angular apps in the same page

About two years ago I was gradually converting an old web app to modern Angular. At some point the app was in a state were the Angular components were embedded as multiple apps at different locations in the page. Very soon I found that one app got the css styling rules from the other, and that the APP_ID that was supposed to be present in the generated html/css (according to the docs:  https://angular.io/guide/component-styles#inspecting-generated-css ) was not there. I made a fix for this, and a pull request to Angular and am very happy now see that my fix for this is finally included here So now you should also be able to use Angular for creating multiple standalone widgets, adverts in any web page that is not made in Angular. That could be news sites, blogs, portals or anything. Angular just got new significant areas of use
Recent posts

Webassembly and audioworklet

Have been playing a lot recently with webassembly and the upcoming audioworklet web standard. This is exciting and powerful technology, opening up for serious use of the web in production of audio and music. Follow the links from my homepage petersalomonsen.com for live demo and more resources.

Using Angular i18n translation strings outside templates

As of today in Angular 6 i18n is only available in the templates. So what if we want to use translated messages programatically and outside templates? I still use the component template html file to declare the message to be translated, but by obtaining the TemplateRef ViewChild in the component typescript file I can get the translated messages from typescript. <ng-template #boardInvitationEmailBody let-organization="organization" let-url="url"> <ng-container i18n>You have been invited to join the board portal for</ng-container> {{organization}}. <ng-container i18n> Please follow the link to: </ng-container> {{url}} </ng-template> So in the typescript code i can now call the createEmailBodyTranlated text method to get the translated text for use outside the template. @ViewChild('boardInvitationEmailBody') boardInvitationEmailBody: TemplateRef ; createEmailBodyTranslatedText(org

Using GIT for offline web app syncing and storage

Offline web applications, progressive web apps (PWA) using service workers for being available offline also needs a way to sync changes with the server. Mostly we store data in JSON documents, and we could identify changes per line - which is something GIT is excellent at. So how could we make the browser a GIT client? I've been working on this for some months now, and compiled libgit2 to webassembly using emscripten - and it turns out to work very well. Some video demos: Cloning a repository: https://youtu.be/rcBluzpUWE4 Merging of file changes: https://youtu.be/xfGrMwLy_tw The project is here: https://github.com/fintechneo/angular-git-filebrowser

Angular for Java EE developers

Being a Java EE developer for a long time and trying to find a development platform in these times where more and more business logic is placed in the frontend code, Angular (NOT AngularJS) became a natural choice. Being used to Java Server Faces with backend beans, coding with Angular is quite similar. You still have a HTML template and a separate class (Angular components ) with the template logic, but now this is all part of the frontend code. Also quite a bit of the code you would earlier place in EJB session beans can be put in Angular services , which can be injected into components using dependency injection . All together with TypeScript which gives you static types, decorations (annotations), classes and interfaces that any Java developer will miss when coding with Javascript. Now that the client / frontend does more and more of the traditional backend work, and the backend is more about providing data and access control than application business logic - Angular is a f

Angular components not reloading on route change

Spent a long time wondering why route changes caused strange effects on my component, and found out that it was because my component wasn't reloading at all. I had this assumption that when a route parameter changed (e.g. /projects/1 changed to /projects/2 ) the component for the route would be reloaded. But this is not the default behaviour of the Angular router. The default behaviour of the Angular router is to reuse the route if the configuration is the same (and not reload the component). But we can override this by providing a RouteReuseStrategy to our @NgModule: providers: [ { provide: RouteReuseStrategy, useClass: AARouteReuseStrategy } ] The full custom implementation of the RouteReuseStrategy will then be like this (and it's the shouldReuseRoute method that changes the behaviour so that the component is reloaded on route parameter change): export class AARouteReuseStrategy extends RouteReuseStrategy { shouldDetach(route: ActivatedRou