title: Implementing angularjs directives as classes in Typescript
body: <p>So after taking a look at some of the examples of angularjs directives in typescript, it seems most people agree to use functions instead of classes when implementing them. </p>
  
  <p>I would prefer to have them as a class and attempted to implement them as follows:</p>
  
  <pre><code>module directives
  {    
      export class search implements ng.IDirective
      {        
          public restrict: string;
          public templateUrl: string;
  
          constructor()
          {            
              this.restrict = 'AE';
              this.templateUrl = 'directives/search.html';
          }
  
          public link($scope: ng.IScope, element: JQuery, attributes: ng.IAttributes)
          {
              element.text("Hello world");
  
          }
      }
  } 
  </code></pre>
  
  <p>Now this works fine. However, I need to have an isolated scope with some attributes and I'm struggling to find out how to include that in the class itself.</p>
  
  <p>logic dictates that since I can have </p>
  
  <pre><code>public restrict: string;
  public templateUrl: string;
  </code></pre>
  
  <p>I should be able to have something like:</p>
  
  <pre><code>public scope;
  </code></pre>
  
  <p>But I'm not sure if this is correct or how to carry on from there (i.e how to add the attributes to the scope).</p>
  
  <p>Anybody know how to solve this? (hopefully, without having to revert to a function if possible)</p>
  
  <p>Thanks,</p>