Skip to content

Instantly share code, notes, and snippets.

@Atefnouri
Created April 9, 2019 07:26
Show Gist options
  • Save Atefnouri/e03cb64117cd75ca3da65bc88db22661 to your computer and use it in GitHub Desktop.
Save Atefnouri/e03cb64117cd75ca3da65bc88db22661 to your computer and use it in GitHub Desktop.
Component With Input && Output
<favorite [is-favoried]="false" (change)="whenFavIsChanged($event)" ></favorite>
<div class="cont" (click)="onClickFav()">
<div *ngIf="isFavoried; else elseBlock" >
<i style="color:#ff4a4a;" class="material-icons"> favorite </i> </div>
<ng-template #elseBlock> <i class="material-icons"> favorite_border </i> </ng-template>
</div>
import { Component, OnInit ,Input , Output, EventEmitter, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'favorite',
templateUrl: './favorite.component.html',
styleUrls: ['./favorite.component.css']
//encapsulation:ViewEncapsulation.Emulated
})
export class FavoriteComponent implements OnInit {
@Input('is-favoried') isFavoried:boolean;
@Output('change') click = new EventEmitter();
constructor() { }
ngOnInit() {
localStorage.setItem('dataSource', 'Atef Nouri');
console.log(localStorage.getItem('dataSource'));
}
public onClickFav = () => {
this.isFavoried = !this.isFavoried;
console.log('the heart was cliked');
this.click.emit({newVal:this.isFavoried});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment