11

I have an issue in Angular 4.

I thinks component in angular doesn't have size (width x height) like this:

Angular issue

So I can't render new component because old component is still there, I can't change value of this.

halfer
  • 19,824
  • 17
  • 99
  • 186
BaoBao
  • 299
  • 1
  • 5
  • 15
  • take a look at this [SO](https://stackoverflow.com/questions/48940252/angular-component-host-element-width-and-height-are-0?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Renaud Apr 19 '18 at 12:57

1 Answers1

37

You can set it manually as follow,

Let's say you have a component called home.component.ts

@Component({
  moduleId: module.id,
  selector: 'home',
  styleUrls: ['home.component.css'],
  templateUrl: 'home.component.html',
)}

So in home.component.css, you can set its height and width as below,

:host {             // host targets selector: 'home'

    display: block;
    left: 0;

    width: 100%;    // takes parent width        
    OR    
    widht: 1000px   // screen of having 1000px of width


    height: 100%;   // takes parent height    
    OR        
    height: 1000px  // screen of having 1000px of height
}
micronyks
  • 54,797
  • 15
  • 112
  • 146
  • Sorry sir, please help me one more. If i render component by ngFor. my old component still have old size and my new component have this size too. Because of that my new component cant show in html. Please help me make component don't have size, only element inside have. Many thanks – BaoBao Aug 15 '17 at 13:37
  • @BaoBao. what happened? – micronyks Aug 15 '17 at 13:39
  • I can't understand your problem completely . – micronyks Aug 15 '17 at 13:47
  • Hi sir @micronyks. I show my issue in my last answer. Please help me. Many thanks. – BaoBao Aug 15 '17 at 14:29
  • 2
    display: block is the key here. It seems that browsers (chrome at least) default to display: inline for elements that aren't known to them. – rooby Dec 06 '18 at 23:39