1

I buy a theme that is working fine on an HTML + CSS simple project approach but I want to transform it into an Angular 6 project.

I managed to put the theme to work on Angular 6 with no problem, but I get a strange CSS behaviour when in an angular 6 application look my code :

<!-- begin:: Page -->
<div class="m-grid m-grid--hor m-grid--root m-page">

  <m-header *ngIf="showContent"></m-header>

  <!-- begin::Body -->
  <div class="m-grid__item m-grid__item--fluid m-grid m-grid--ver-desktop m-grid--desktop m-body">

    <m-leftmenu></m-leftmenu>

    <div *ngIf="showContent" #mContentWrapper>

      <router-outlet></router-outlet>

    </div>

  </div>

  <m-footer></m-footer>

</div>
<!-- end:: Page -->

<!-- begin::Scroll Top -->
<div id="m_scroll_top" class="m-scroll-top">
  <i class="la la-arrow-up"></i>
</div>

<!-- end::Scroll Top -->

this is my code from my PainelComponent ( painel.component.html ), I use a with a lazy load to load my HomeComponent inside the PainelComponent, this is the code from HomeComponent :

<div class="m-grid__item m-grid__item--fluid m-wrapper">

    <!-- BEGIN: Subheader -->
    <div class="m-subheader ">
      <div class="d-flex align-items-center">
        <div class="mr-auto">
          <h3 class="m-subheader__title ">Painel</h3>
        </div>
        <div>
          <span class="m-subheader__daterange" id="m_dashboard_daterangepicker">
            <span class="m-subheader__daterange-label">
              <span class="m-subheader__daterange-title"></span>
              <span class="m-subheader__daterange-date m--font-brand"></span>
            </span>
            <a href="#" class="btn btn-sm btn-brand m-btn m-btn--icon m-btn--icon-only m-btn--custom m-btn--pill">
              <i class="la la-angle-down"></i>
            </a>
          </span>
        </div>
      </div>
    </div>

    <!-- END: Subheader -->
    <div class="m-content">

      <!--Begin::Section-->
      <div class="row">
        <div class="col-xl-12">

        </div>

        <div class="col-xl-12 col-lg-12">

          <!--begin:: Widgets/Quick Stats-->
          <div class="row m-row--full-height">
            <div class="col-sm-12 col-md-12 col-lg-6">
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-brand ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      570
                      <small>All Sales</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_1"></canvas>
                    </div>
                  </div>
                </div>
              </div>
              <div class="m--space-30"></div>
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-danger ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      690
                      <small>All Orders</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_2"></canvas>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-sm-12 col-md-12 col-lg-6">
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-success ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      230
                      <small>All Transactions</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_3"></canvas>
                    </div>
                  </div>
                </div>
              </div>
              <div class="m--space-30"></div>
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-accent ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      470
                      <small>All Comissions</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_4"></canvas>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <!--end:: Widgets/Quick Stats-->
        </div>

      </div>
      <!--End::Section-->


    </div>
  </div>

This is the approach that I DON'T WANT ( THIS IS IN ANGULAR 6 WITH ):

Style that i don't want

But when i pick all the code from HomeComponent, erase this line from PainelComponent :

<div *ngIf="showContent" #mContentWrapper>

      <router-outlet></router-outlet>

    </div>

and put all the code from HomeComponent it works as I expected with a Full-Width Wrapper 100%, Why this? What I must do to work with router, I was thinking that Angular just add the HTML file from a component but I guess is not like this.

This is the code when i put the home.component.html inside the painel.component.html

<!-- begin:: Page -->
<div class="m-grid m-grid--hor m-grid--root m-page">

  <m-header *ngIf="showContent"></m-header>

  <!-- begin::Body -->
  <div class="m-grid__item m-grid__item--fluid m-grid m-grid--ver-desktop m-grid--desktop m-body">

    <m-leftmenu></m-leftmenu>


  <div class="m-grid__item m-grid__item--fluid m-wrapper">

    <!-- BEGIN: Subheader -->
    <div class="m-subheader ">
      <div class="d-flex align-items-center">
        <div class="mr-auto">
          <h3 class="m-subheader__title ">Painel</h3>
        </div>
        <div>
          <span class="m-subheader__daterange" id="m_dashboard_daterangepicker">
            <span class="m-subheader__daterange-label">
              <span class="m-subheader__daterange-title"></span>
              <span class="m-subheader__daterange-date m--font-brand"></span>
            </span>
            <a href="#" class="btn btn-sm btn-brand m-btn m-btn--icon m-btn--icon-only m-btn--custom m-btn--pill">
              <i class="la la-angle-down"></i>
            </a>
          </span>
        </div>
      </div>
    </div>

    <!-- END: Subheader -->
    <div class="m-content">

      <!--Begin::Section-->
      <div class="row">
        <div class="col-xl-12">

        </div>

        <div class="col-xl-12 col-lg-12">

          <!--begin:: Widgets/Quick Stats-->
          <div class="row m-row--full-height">
            <div class="col-sm-12 col-md-12 col-lg-6">
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-brand ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      570
                      <small>All Sales</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_1"></canvas>
                    </div>
                  </div>
                </div>
              </div>
              <div class="m--space-30"></div>
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-danger ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      690
                      <small>All Orders</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_2"></canvas>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-sm-12 col-md-12 col-lg-6">
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-success ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      230
                      <small>All Transactions</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_3"></canvas>
                    </div>
                  </div>
                </div>
              </div>
              <div class="m--space-30"></div>
              <div class="m-portlet m-portlet--half-height m-portlet--border-bottom-accent ">
                <div class="m-portlet__body">
                  <div class="m-widget26">
                    <div class="m-widget26__number">
                      470
                      <small>All Comissions</small>
                    </div>
                    <div class="m-widget26__chart" style="height:90px; width: 220px;">
                      <canvas id="m_chart_quick_stats_4"></canvas>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <!--end:: Widgets/Quick Stats-->
        </div>

      </div>
      <!--End::Section-->


    </div>
  </div>


  </div>

  <m-footer></m-footer>

</div>
<!-- end:: Page -->

<!-- begin::Scroll Top -->
<div id="m_scroll_top" class="m-scroll-top">
  <i class="la la-arrow-up"></i>
</div>

<!-- end::Scroll Top -->

This is the approach that I WANT:

Style that i want

Wavrik
  • 61
  • 9
  • please show your `home.component.html` code when you use **painel.component** inside – Florian Dec 04 '18 at 15:32
  • Thank you for respond, i edit the question. – Wavrik Dec 04 '18 at 15:35
  • Can you tell me what is the selector of home.component ? I can't see it inside the html you copy/pasted – Florian Dec 04 '18 at 15:40
  • I use to load the home.component.html inside the painel.component.html this is my router : const appRoutes: Routes = [ { path: '', component: PainelComponent, canActivate: [AuthGuard], children: [ { path: '', loadChildren: './layout/home/home.module#HomeModule' } ] } ]; – Wavrik Dec 04 '18 at 15:43
  • In your `home.component.ts`, you have `@Component` decorator, and you have `selector`string property, what is it? – Florian Dec 04 '18 at 15:48
  • this is the selector 'm-home' – Wavrik Dec 04 '18 at 16:02

1 Answers1

0

Angular uses shadow-dom browser's capability to render your component (using ViewEncapsulation).

If you pay attention, you should notice that using <m-home> adds a node inside your html tree.

An easy solution is :

  • In your home.component.ts, change your selector to div[m-home] insteaad of m-home
  • In your home.component.html remove the first <div> (and ensure to delete enclosing bracket at the end).
  • Now, in the template where you use <m-home>, replace it by : <div m-home class="m-grid__item m-grid__item--fluid m-wrapper"> </div>

Check your html tree again, you will notice the difference

Florian
  • 1,473
  • 10
  • 15
  • Great answer now is working, but why this? How can i simple add a element like html, i see something like ng-content, ng-template. Why this node from is a problem? – Wavrik Dec 04 '18 at 18:35
  • @Wavrik : let's say your **css selectors** apply a specific style for all child of a given element. You expect to have a structure such as : `parent>div-child`. With your `m-home` component you had : `parent>m-home>div-child`, so your style couldn't apply to `div-child` because it wasn't a first-child anymore, `m-home` component was placed between parent and child, breaking your css. – Florian Dec 05 '18 at 08:26