1

I'm having a strange display of a page when I add an interpolation to generate the code I want (Angular).

static way : display ok ; when using the tag I created, it's not, as you can

see on this screenshot.

I use Bootstrap on node.js project with Angular. The code is :

  <ul id="listEvents" class="dropdown-menu dropdown-alerts" *ngIf="isMultipleEvents()">
    <app-event-item  *ngFor="let event of events"
    [hashtag] = "event.hashtag"></app-event-item>
      <li>
          <a href="#">
              <div>
                  <button type="button" class="btn btn-warning btn-xs">#SCS2018</button>
              </div>
          </a>
      </li>
      <li class="divider"></li>
      <li>
          <a href="#">
              <div>
                <button type="button" class="btn btn-warning btn-xs">#WKSH2019</button>
              </div>
          </a>
      </li>
      <li class="divider"></li>
      <li>
          <a class="text-center" href="#">
              <strong>Mes paramètres</strong>
              <i class="fa fa-angle-right"></i>
          </a>
      </li>
  </ul>

and the event-item compononent code is :

          <li>
          <a href="#">
              <div>
                  <button type="button" class="btn btn-warning btn-xs">{{ hashtag }}</button>
              </div>
          </a>
      </li>
      <li class="divider"></li>

When I look for the HTML generated in dev tools (Chrome), I see

ul > app-event-item > li > a > div > button

then

ul > li > a > div > button

for the statics one.

So the only difference is this level "app-event-item" that I created with Angular, but I don't understand why it change the way it look.

Nisarg
  • 1,631
  • 6
  • 19
  • 31
jpluton
  • 38
  • 5
  • 1
    Pretty sure, regardless of anything else, links cannot have `button`s as descendants...it's invalid HTML – Paulie_D Aug 17 '18 at 16:17
  • Or any block level elements. You would want the `(click)` function for that. Outside of that, I am not sure which element you are actually trying to target. Wouldn't you use a custom class, like `.my-element-style {}` and add it to the element? – Taylor Ackley Aug 17 '18 at 16:19
  • https://stackoverflow.com/questions/6393827/can-i-nest-a-button-element-inside-an-a-using-html5 – Paulie_D Aug 17 '18 at 16:19
  • 1
    I don't think this is an issue with the button being a descendent of the anchor tag. @jpluton can you include your CSS? I think it's more of an issue of `
  • ` not being a direct descendent of `
      ` but you can work around that by setting styles to `:host` in your component's css file.
  • – Michael Sorensen Aug 17 '18 at 16:49
  • I think it's actually an Angular issue : I've got the same issue on other part of pages : I got a bootstrap static theme (I didn't write the css, just got a theme ready-to-use, and I'm trying to dynamise it with Angular. So when I replace static blocs like the
  • by an angular component, my source has a new tag (the one I created, here , and I guess the CSS is bothered by this tag. I think I forget a step like "how could I update or reference the bootstrap css I got in the Angular integration"...
  • – jpluton Aug 19 '18 at 06:34
  • OK writing help me to think...A solution worked, but it's ugly and I think just pointing the problem, I compared each CSS in the chrome toolkit, and found a .dropdown-menu > li > a (inherited from bootstrap) not present for the dynamic version. When I rewrite this in my css component it's Ok (but bad, due to the duplication...) – jpluton Aug 19 '18 at 06:58