简体   繁体   中英

What's the best way to write directives?

I've been struggling with the way to implement a good structure for directives in TypeScript. I've found couple of solutions online, however to be honest, I have no idea which one to use - they all do their job.

What is a good structure for a directive to stick to?

nb I'm using AngularJS 1.

In my opininion, thinking on Typescript Way, you need to import the AngularJS definition , this gives you references on the framework.

  1. Create a Module
  2. Export a Function that returns a Angular Directive Definition Object
  3. In ddo use the APIs as you wish

    [...] export function tsDirective(): ng.IDirective [...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM