 ElementRef, HostListener, Renderer, Input } from '@angular/core';

@Directive({
  selector: '[workItemResize]'
})

export class WorkItemResizeDirective implements ngAfterViewInit {

  private el: HTMLElement;
  private renderer: Renderer;

  constructor(el: ElementRef, public renderer: Renderer)
  { 
    this.el = el.nativeElement; 
    this.renderer = renderer;
  }  


  @HostListener('window:resize', ['$event.target']) 
  onResize() 
  { 
    this.resizeWorks();
  }

  ngAfterViewInit() {
    this.resizeWorks();
  }

  private resizeWorks(): void {
    this.renderer.setElementStyle(this.el, 'height', this.el.width); // <-- doesn't work I kow that this.el.width doesn't exist but just for demonstration purpose
    this.renderer.setElementStyle(this.el, 'height', '500'); // <-- works
  }

}

projects.template.html
<div class="posts row">
        <div class="work-item col-xs-12 col-sm-6 col-no-padding"  workItemResize *ngFor="let post of posts">

                <!-- show some fancy image -->
                <div class="img"  [ngStyle]="{'background-image':'url('+post.better_featured_image.source_url+')'}"></div>

        </div>
</div>

Related:
https://github.com/angular/angular/issues/6515

A: I tested this way and simply worked! It seems that binding did this job.
<div #foto [style.height.px]="foto.getBoundingClientRect().width / 2">


A: You can get the width of the component itself if that one has a display property defined (such as 'block' in the example below). Note that you should be able to define this style (using dom shadowing):
:host {
    display:block;
}

If you are not using dom shadowing (Ionic 2-3):
my-component {
    display:block;
}

Here is the controller (exposing the width as an observable):
import {AfterViewInit, Component, ElementRef, HostListener, Input} from '@angular/core';
import {Subject} from 'rxjs/Subject';

@Component({
    selector:'my-component',
    template: '{{$width|async}}',
    style:'my-component {display: block;}'
})
export class MyComponent implements AfterViewInit {
    @Input() public gridWidth: number;
    private $width: Subject<number> = new Subject();

    constructor(private elementRef: ElementRef) {
    }

    public ngAfterViewInit(): void {
        this.emitWidth();
    }

    @HostListener('window:resize', ['$event.target'])
    public onResize(): void {
        this.emitWidth();
    }

    private emitWidth(): void {
        this.$width.next(this.getWidth());
    }

    private getWidth(): number {
        return this.getNativeElement().clientWidth;
    }

    private getNativeElement(): HTMLElement {
        return this.elementRef.nativeElement;
    }
}


A: I don't know a way to get the width from the host element without accessing nativeElement but setting could be done like:
@HostListener('window:resize', ['$event.target']) 
onResize() { 
  this.resizeWorks();
}

@HostBinding('style.height.px')
elHeight:number;

private resizeWorks(): void {
  this.elHeight = this.el.nativeElement.width;
}

If you can add an element inside your components template like
<div style="width: 100%;" #div (window:resize)="elHeight = div.getBoundingClientRect()">
  <!-- your template here -->
</div>

then this would work without direct DOM access at all (but not after init).

A: I tried out @GünterZöchbauer solution and refined it. You do not need HostListener to get bounds of div. Like with 'click' or other event (event)="function()", it will fire this function. I hope someone will find this helpful.
<div #div (window:resize)="onResize(div.getBoundingClientRect())">
   <!-- your template here -->
</div>


onResize() { 
   this.resizeWorks();
}

@HostBinding('style.height.px') elHeight:number;

private resizeWorks(): void {
   this.elHeight = this.el.nativeElement.width;
}

(#div) - this is variable needed to get measurement target. It does not have to be same name as element, it can be any name.
One more way to get element dimensions is to use ElementRef class from Angular Core, but then you have to find that child element which has width and height properties. I used this in Angular 2 Maps to get container width and height, but i found out that, using this method i had to find in element tree element which had these properties and it was second child of root element. It is more messy.
ElementDimensions - is just a class with height and width which I made to contain those properties.
<div (window:resize)="onResize()">
   <!-- your template here -->
</div>

private getContainerDimensions(): ElementDimensions{
    var rootElement = this.elementRef.nativeElement;
    var childElement = rootElement.firstElementChild;
    var contentElement =  childElement.firstElementChild;

    return {
        height:contentElement.clientHeight,
        width: contentElement.clientWidth
    };
}

how can I alter recipe to make in 13 x 9 x 2 sheet cake?
I would like to make a two-layer sheet cake if possible. Sounds incredibly good!
for holds 8 cups. A 9x13 pan holds 14 cups. 14/8 = 1.75 but increasing the ingredients by 75% is too complicated so I would do one and a half the recipe for a 9x13 pan.
Read the recipe comments carefully.
There is a conversation at the end of March 2018 between the recipe author and forum participant Angie C. concerning a nearly identical alteration.
Luckily for F52 readers Angie C. was thoughtful enough to follow up on April 1, 2018 about what worked for her. Too often in Internet Q&A forums people do not follow up with what actually worked for them.
the cake part of the Boston Cream Pie???Using grapes from the Nord Family vineyards in Yountville and Oakville, our Cabernet Sauvignon is 100% free-run juice. It is aged for 18 months using 40% new French barrels and another 6+ months in the bottle prior to release. This wine strikes an elegant balance between voluptuous dark fruit components and soft, plush tannins. On the palate, the wine offers concentrated flavors of ripe Bing cherry and dark chocolate that stay present through a long, satisfying finish.The Lionesses couldn't contain their excitement as they turned the media room into a frenzy.
In November 2018 (9 months after I'd started my online biz), I emailed my list and told them I quit. I was shutting up shop.
Being an "entrepreneur" was SO much more work than I anticipated.
Cue massive burnout. So... I emailed everyone and announced that I would quit.
Well actually, it wasn't quite like that.
That's the funny thing about a calling: it just won't leave you alone.
I was out at dinner with a friend who was going through IVF. She burst into tears in the middle of the restaurant as she shared her experience.
"That's not right," I demanded.
"It shouldn't be like this"
... and as I uttered those words I realised that my work wasn't done.
Nobody should have to experience what I had experienced, and I was one of the ones who could help change the story of others.
And let's be honest: I'm not like my 'non-entrepreneur' friends.
Even though I felt jaded.

I didn't need to quit...
I needed to do things differently.
I didn't need to quit. I needed to get strategic.
Financially, my business was doing ok but.... It felt like I was going so slowly.
I tried to sign up to their mailing lists and I desperately analysed their Instagram profiles to find out what THEY were doing that I wasn't.

So then I worked with coaches who were great... but there was just something I'd always leave feeling like their advice wasn't tailored to businesses like mine (fertility and general business coaching are two very different beasts) so the strategies and advice never hit the same.
Turns out my business was NOT sustainable at all, and it's no surprise that when the wobbles