I have this directive:
angular.module('exampleApp').directive('exampleDirective', ['$document', '$window', function($document, $window) {
return {
restrict: 'E',
scope: false,
template: '<div class="foo"></div>',
link: function($scope, $element, $attrs) {
var targetElement = angular.element(document.querySelector($attrs['targetSelector']));
console.log(targetElement.css('height'));
}
}
]);
Which works fine with this html:
<div id="div1" style="height: 100px">A div</div>
<example-directive target-selector="#div1" />
Because in the console I see: "100px" printed out
But with this html:
<style>
.div-example {
height: 100px;
}
</style>
<div id="div2" class="div-example">A div</div>
<example-directive target-selector="#div2" />
Which is basically the same but without inline-style, the directive is simply not working. The console is printing: "" (empty string).
How do I solve this?
I tried scope: true
but it didn't work either.
Is targetElement.css('height')
only good for inline style?