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.
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....
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 ...
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 ...