JavaScript How to deal with css and custom directive in angulajs deal with custom,deals custom woodworks,how to deal with

Consider a custom directive in angularjs:

.directive('myDir', function() {
  return {
    restrict: 'E',
    template: "..."
  }
})

As far as I see the tag <my-dir></myDir> has no default style associated (or, at least, it is not a block tag). Now I want to style it and place in the right point of my page. I have 2 alternatives:

1) Use this template:

.directive('myDir', function() {
  return {
    restrict: 'E',
    template: "<div class="layout">...</div>",
  }
})

And css:

.layout {
    /* bla bla bla */
}

But this introduce a new unnecessary level in the DOM three, since if I wrote something like <my-dir class="layout"></my-dir> with the proper css attached it would have worked anyway BUT I'll have to remember to add the same css class every time I use <my-dir> inside my code (and this is not DRY).

2) This led me to add style inside post-link function:

.directive('myDir', function() {
  return {
    restrict: 'E',
    template: "...",
    link: function(scope, element, attrs) {
      element.addClass('layout');
    }
  }
})

Which strategy is better? Are there pros or cons I can't see?

UPDATE:

Using replace: true in directive definition is not an option, since it has been deprecated and when using bootstrap things like <my-dir class="visible-xs"></my-dir> may be useful.

Answer:1

let suppose I have an array var a = [1,2,3,4] and now I want to print this array from the back side like 4,3,2,1 I know this can we achieve by this for(let i=a.length; i>= 0; i--) { console....

let suppose I have an array var a = [1,2,3,4] and now I want to print this array from the back side like 4,3,2,1 I know this can we achieve by this for(let i=a.length; i>= 0; i--) { console....

  1. print array element python
  2. print array element bash
  3. print array element php
  4. print array elements in java
  5. print array elements in c
  6. print array elements javascript
  7. print array elements in reverse order java
  8. print array elements in shell script
  9. print array elements perl
  10. print array elements using recursion java
  11. print array elements in reverse order c++
  12. print array elements in new line javascript
  13. print array elements in reverse order javascript
  14. print array element matlab
  15. print array elements in ascending order
  16. print array elements using recursion in c
  17. print array elements in one line java
  18. print array elements using pointers
  19. print array elements in scala
  20. print array elements in java 8

I've written the following code that generates a select list. However, the part where it's supposed to check if this.id equals the same as the existing_code and put the selected value in doesnt seem ...

I've written the following code that generates a select list. However, the part where it's supposed to check if this.id equals the same as the existing_code and put the selected value in doesnt seem ...

  1. javascript foreach select options
  2. javascript foreach select

In VueJS, I have seen different ways of accessing parent properties from a component. Say I want to use the parent property items in my component. First way The component has a props value bound to ...

In VueJS, I have seen different ways of accessing parent properties from a component. Say I want to use the parent property items in my component. First way The component has a props value bound to ...

My application architecture is simple Front end using ionic-angularjs with backend nodejs interfacing with mongodb. My application will require ability to submit data related to reimbursement (say few ...

My application architecture is simple Front end using ionic-angularjs with backend nodejs interfacing with mongodb. My application will require ability to submit data related to reimbursement (say few ...