1

I have a code block like:

  <div class="col-md-12">
    <div class="row">
      <ng-template dynamicComponents></ng-template>
    </div>
  </div>

dynamicComponents is a directive using which I inject dynamic components.

All the application is using Bootstrap and is working fine but the dynamically injected components are shrinking or not working with bootstrap css, I even tried using encapsulation: ViewEncapsulation.None but it doesn't seem to work.

Please refer the screenshots below:

enter image description here

Here everything works fine till class=row and it is taing the full width, but once a dynamic component named app-from-builder-components-editor is injected it breaks up the bootstrap properties, please see below:

enter image description here

What can I do to get the bootstrap properties to work ?

6
  • How is bootstrap integarted in you app? css in index,html or scss iincluded in styles.scss? Commented May 28, 2020 at 17:42
  • @Marc it is used from css in angular.json Commented May 28, 2020 at 17:45
  • A workaround is to use angular material and angular flex layout: tburleson-layouts-demos.firebaseapp.com/#/docs. Commented May 28, 2020 at 17:55
  • remove it from the angular.json file and write this in your styles.css @import 'bootstrap/dist/css/bootstrap.css' Commented May 28, 2020 at 17:55
  • @Flightdoc5242 does not work that way either, I have already tried placing the file at separate locations / methods Commented May 28, 2020 at 17:58

2 Answers 2

1

The problem is your component host (app-form-builder-components-editor) that sits between your row and col divs. To make it work, your 'col-md-12' div should be a direct child of your 'row' div.

What you could do is putting the <div class="row"> inside your app-form-builder component's template to work around this issue.

Sign up to request clarification or add additional context in comments.

Comments

1

I solved this by using containers:

<ng-template>
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <!-- content --> 
      </div>
    </div>
  </div>

  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <!-- content --> 
      </div>
    </div>
  </div>
</ng-template>

Not ideal, but it seems to stop the layout issue. Angular templates seem to rewrite the DOM and nest the rows, for some reason. This "resolves" the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.