I have several Directives which are very similar in some regard, but very different in others. To reduce the amount of duplicate code inheritance can be used, however I have not yet figured out how to instantiate a directive Class.
Here is what I have tryed:
/// <reference path='../_all.ts' />
module app.directives {
'use strict';
export class myDirective implements ng.IDirective
{
private margin = {top: 70, right: 20, bottom: 40, left: 55};
private padding = {top: 10, right: 10, bottom: 10, left: 10};
public restrict = 'A';
public $scope = {
regulationdata: "=",
title: "="
};
constructor(private $window) {}
public link($scope, element: JQuery, attr: ng.IAttributes)
{
// Browser onresize event
this.$window.onresize = function () { // TypeError: Cannot read property '$window' of undefined
$scope.$apply();
};
// lots of application specific code.
}
}
/** Register directive */
angular.module('app').directive('myDirective',['$window', ($window) => { return new myDirective($window); } );
}
The error I receive is: TypeError: Cannot read property '$window' of undefined