0

Basically there is a wrapping problen in which dom element of custom component does not cover their children.

There is a single page which uses test component.

single.html

<test></test>

single.ts

import { Component } from '@angular/core';
import { IonicPage,} from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-single',
  templateUrl: 'single.html',
})
export class SinglePage {}

single.scss

page-single {}

Now this test component

test.html

<div>
  <div>Hello</div>
  <div>Hello</div>
  <div>Hello</div>
  <div>Hello</div>
</div>

test.ts

import { Component } from '@angular/core';

@Component({
  selector: 'test',
  templateUrl: 'test.html'
})
export class TestComponent {}

test.scss

test {}

inspect mode in chrome

  1. Why it looks test and inside div elements are siblings to test and are not like parent child?

  2. Changing background-color:red on test (in chrome inspect mode) does nothing visually, meaning all children div color remains same.

Full test element is not highlighted. Inside div elements are fine. test component shows 411 x 68 but looks like it is 0x0. Computed styles show dimension as auto x auto. Every component in my app is behaving like this. Component do not cover their child and looks like their sibling.

This behaviour was also present in Ionic example conference app. In Angular example app components works as expected.

1 Answer 1

1

Add :host { display:block; background:red; } in test.scss

This is because browsers don't recognize <test> as a a block element. Other than that, it's working as intended and if you look at the dom tree more carefully, you'll see that the div is inside test.

:host is a pseudo which refers to the component element itself - test {} does nothing unless there's another test inside like <test><test></test></test>, then it'd affect the child.

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

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.