Communicate between controllers in Angular by using a simple pubsub service in TypeScript.


I created a really simple angular PubSubService in TypeScript, to allow communication between controllers or directives or services.


In the example below, controller 1, fires an event and controller 2 reacts to the firing of the event.



module dev {
    "use strict";

    var appModule = angular.module("myApp", []);

    appModule.controller("MyController1", ["$scope", "pubSubService", ($scope, pubSubService)

    => new dev.MyController1($scope, pubSubService)]);

    appModule.controller("MyController2", ["$scope", "pubSubService", ($scope, pubSubService)
    => new dev.MyController2($scope, pubSubService)]);



    export class MyController1 {
        constructor(public $scope: ng.IScope, public pubSubService: PubSubService) {
            // Fire an an event
            pubSubService.publish("my-custom-event", "some publisher data");

    export class MyController2 {
        constructor(public $scope: ng.IScope, public pubSubService: PubSubService) {
            this.handleMyCustomEvent = this.handleMyCustomEvent.bind(this);

            // Subscribe to be notified, when "my-custom-event" is fired.
            pubSubService.subscribe("my-custom-event", this.handleMyCustomEvent);
        handleMyCustomEvent(data: any) {
        // Do something, when an event is fired from MyController1.


     * This service can be used to share data between controllers by using a pub sub mechanism.
    export class PubSubService {
        private nextListenerIndex: number;
        private listeners: Array<IListener>;

        constructor() {
            this.listeners = [];
            this.nextListenerIndex = 0; // The first subscription will be located at index 0;

            this.publish = this.publish.bind(this);
            this.subscribe = this.subscribe.bind(this);
            this.unsubscribe = this.unsubscribe.bind(this);

         * Publish an event.
         * All subscribers will be notified.
         * @param name, is the name of the event and is case insensitive.
        publish(name: string, data?: any) {
            for (var i = 0, length = this.listeners.length; i < length; i++) {
                const listener = this.listeners[i];
                if (listener && === name.toLowerCase()) {
          , data, listener.subData);

         * Subscribe to be notified, when an event is published.
         * @param name, is the name of the event and is case insensitive.
         * @returns A token, that can be used to unsubscribe.
        subscribe(name: string, handler: (data?: any, subData?: any) => void, data?: any): number {
            var token = this.nextListenerIndex;
            this.listeners[token] = {
                handler: handler,
                name: name,
                subData: data
            this.nextListenerIndex += 1;

            return token;

         * Remove the event listener subscription.
         * @param token received on subscribing to an event listener.
        unsubscribe(token: number) {

            // This will create holes in the array, but for now we do not care.
            this.listeners[token] = null; 

    export interface IListener {
        // This function will be called when an event is published.
        // Data is the data from the publisher, subData is the data from the subscriber.
        handler: (data?: any, subData?: any) => void;
        name: string;
        subData?: any; // Data from the subscriber.

    angular.service("pubSubService", () => new PubSubService());

Autofill issues: This is the first time, Chrome disappoints me

When I set the attribute “autocomplete” to the value “off” on a form element, I expect Chrome, to NOT autofill fields in the form, but that’s not the case.


Even if you also add the autocomplete attribute to the input element with value “off”, this is not the case.


To get it working I had to add autocomplete=”off” to the form tag and add autocomplete=”new-password” to the <input type=”password” /> field.

How to use angular in a fancybox dynamically shown by jquery

In a brownfield application I encountered a old fancybox jquery plugin. This plugin was used throughout the whole application. This fancybox is just a modal dialog.

I wanted the content of the fancybox to be handled by angular.


To accomplish this, I used the following code:





You can find the code at:

Fix: Visual Studio doesn’t use or can’t find TypeScript typings (*.d.ts) in a .net core project


I added some TypeScripts typings to a .net core project in Visual Studio 2015  (version 14.0.25123.00 Update 2), by using the NPM package “typings”, but the added *.d.ts files, were not picked up by Visual Studio, this was caused by excluding the “wwwroot” folder in the tsconfig.json,


after removing the wwwroot folder from the exclude array, the typings were correctly found and used.




  "compileOnSave": true,
  "compilerOptions": {
    "module": "system",
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es6"
  "exclude": [

     "wwwroot" <========================= Remove the wwwroot

Yes, Yes–Integrated Terminal in Visual Studio Code


The killer feature I was missing in Visual Studio Code was a integrated terminal.


More and more I use the command line for all kinds of tasks, but I don’t want to leave my editor, so I’m very glad that the visual studio code team decided to create a integrated terminal, currently it can only by found in the insiders builds, but a stable release containing the integrated terminal is on it’ s way.


To open the integrated terminal hit CTRL + `.


Event the shortcut is convenient Smile.


So to install all the npm packages in your project just hit CTRL + ` and enter npm install: