Writing an Angular directive with a TypeScript class

前端 未结 1 1901
不知归路
不知归路 2021-01-22 01:44

I may just be attempting to combine too many \"new-to-me\" concepts at once, but I am trying to write a custom Angular directive using a TypeScript class. At the moment, I\'m no

相关标签:
1条回答
  • 2021-01-22 02:05

    Though it is not quite the same question, this answer included an example of what I'm attempting to do: How can I define my controller using TypeScript?

    I followed the example in the Plnkr it referenced and found success: http://plnkr.co/edit/3XORgParE2v9d0OVg515?p=preview

    My final TypeScript directive looks like:

    module App {
        'use strict';
    
        export class appStepper implements angular.IDirective {
    
            public link:(scope:angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes) => void;
            public template:string = '<div>0</div><button>-</button><button>+</button>';
            public scope = {};
            public restrict:string = 'EA';
    
            constructor(){ }
    
        }
    
        angular.module('app').directive('appStepper', [() => new App.appStepper()]);
    }
    
    0 讨论(0)
提交回复
热议问题