Skip to content

Instantly share code, notes, and snippets.

View philipszdavido's full-sized avatar

Chidume Nnamdi philipszdavido

View GitHub Profile
//src/components/linktext/linktext.component.ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-linktext',
templateUrl: './linktext.component.html',
styleUrls: ['./linktext.component.css']
})
export class LinktextComponent implements OnInit {
//src/app/components/points/points.component.html
<a href="#" class="label label-success link-black btn btn-sm">
<i class="fa fa-gift margin-r-5"></i> Points ({{points}})
</a>
//src/app/components/points/points.component.ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-points',
templateUrl: './points.component.html',
styleUrls: ['./points.component.css']
})
export class PointsComponent implements OnInit {
import * as fromArticle from '../../redux/reducer'
import * as fromAction from '../../redux/actions/articles'
import { Article } from '../../redux/models/article';
import { Store } from '@ngrx/store'
//inject the Store inside your components constructor
constructor(private store: Store<fromArticle.State>) { }
<app-linktext [titletext]='article.title' [linktext]='article.link'> </app-linktext>
<app-votelink [points]='article.points' (upvote)='upvote($event)' (downvote)='downvote($event)'></app-votelink>
upvote = () => {
this.store.dispatch(new fromAction.IncrementArticlePointAction(this.article))
}
downvote = () => {
this.store.dispatch(new fromAction.DecrementArticlePointAction(this.article))
}