You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+102-7Lines changed: 102 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -510,7 +510,108 @@ Many of my styles have been from the many pair programming sessions [Ward Bell](
510
510
**[Back to top](#table-of-contents)**
511
511
512
512
## Directives
513
-
TODO
513
+
- **Limit 1 Per File**: Create one directive per file. Name the file for the directive.
514
+
515
+
*Why?*: It is easy to mash all the directives in one file, but difficult to then break those out so some are shared across apps, some across modules, some just for one module. Also easier to maintain.
516
+
517
+
```javascript
518
+
/* avoid */
519
+
angular
520
+
.module('app.widgets')
521
+
522
+
/* order directive that is specific to the order module */
/* spinner directive that can be used anywhere across apps */
550
+
.directive('sharedSpinner', sharedSpinner);
551
+
552
+
/* implementation details */
553
+
```
554
+
555
+
- **Limit DOM Manipulation**: When manipulating the DOM directly, use a directive. If alternative ways can be used such as using CSS to set styles or the [animation services](https://docs.angularjs.org/api/ngAnimate), Angular templating, [`ngShow`](https://docs.angularjs.org/api/ng/directive/ngShow) or [`ngHide`](https://docs.angularjs.org/api/ng/directive/ngHide), then use those instead.
556
+
557
+
*Why?*: DOM manipulation can be difficult to test, debug, and there are often better ways (e.g. CSS, animations, templating)
558
+
559
+
- **Restrict to Elements and Attributes**: When creating a directive that makes sense as a standalone element, allow restrict `E` (custom element) and optionally restrict `A` (custom attribute). Generally, if it could be its own control, `E` is appropriate. General guideline is allow `EA` but lean towards implementing as an element when its standalone and as an attribute when it enhances its existing DOM element.
560
+
561
+
*Why?*: It makes sense.
562
+
563
+
*Why?*: While we can allow the directive to be used as a class, if the directive is truly acting as an element it makes more sense as an element or at least as an attribute.
0 commit comments