When I use Angularjs transclusion it seems to break styling which uses on child selector css
rules. For instance below I'm creating the default Bootstrap panel directly:
<div class="panel panel-default">
<div class="panel-heading">
panel heading
</div>
<div class="panel-body">
panel body
</div>
</div>
But using Angularjs directives, in theory, I can hide the Bootstrap panel css like this...
<my-panel>
<my-panel-heading>
my panel heading
</my-panel-heading>
<my-panel-body>
my panel body
</my-panel-body>
</my-panel>
And maybe add some customisations. My directives would look like this...
angular.module('myApp')
.directive('myPanel', [ function() {
var directive = {
transclude: true,
restrict: 'E',
scope: {},
template: '<div class="panel panel-default" ng-transclude></div>'
}
return directive;
}]);
angular.module('myApp')
.directive('myPanelHeading', [ function() {
var directive = {
transclude: true,
restrict: 'E',
scope: {},
template: '<div class="panel-heading" ng-transclude></div>'
}
return directive;
}]);
angular.module('myApp')
.directive('myPanelBody', [ function() {
var directive = {
transclude: true,
restrict: 'E',
scope: {},
template: '<div class="panel-body" ng-transclude></div>'
}
return directive;
}]);
Unfortunately the styling is now broken. When I examine the generated html, Angularjs has added tags to the html for the scope...
<my-panel>
<div class="panel panel-default" ng-transclude="">
<my-panel-heading class="ng-scope"> <!-- is this breaking the child selector rule? -->
<div class="panel-heading" ng-transclude="">
I'm still new to Angularjs and CSS, so am I right about this? Is this what is causing the styling to break? And if so wouldn't this cause endless problems if you use Angularjs with Bootstrap or Foundation or is there a simple workaround? Here is the fiddle.
Any advice on avoiding this problem is much appreciated!
EDIT: Here's a screenshot of (what I think is) the relevant CSS from Bootstrap...
I'm guessing that the link between panel-heading
and panel-default
is broken?