17.10.2018 Views

Angular

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

store,<br />

effects<br />

],<br />

providers: [],<br />

bootstrap: [AppComponent]<br />

})<br />

export class AppModule { }<br />

app.component.ts<br />

import { Component } from '@angular/core';<br />

import { Store } from '@ngrx/store';<br />

import { Observable } from 'rxjs';<br />

import { IAppState } from './Store/index';<br />

import { simpleActionTpye } from './Store/simple/simple.action';<br />

@Component({<br />

selector: 'app-root',<br />

templateUrl: './app.component.html',<br />

styleUrls: ['./app.component.css']<br />

})<br />

export class AppComponent {<br />

title = 'app';<br />

}<br />

constructor(private store: Store) {<br />

store.select(s => s.sum).subscribe((res) => {<br />

console.log(res);<br />

})<br />

this.store.dispatch({<br />

type: simpleActionTpye.add,<br />

payload: 1<br />

})<br />

this.store.dispatch({<br />

type: simpleActionTpye.add,<br />

payload: 2<br />

})<br />

this.store.dispatch({<br />

type: simpleActionTpye.add,<br />

payload: 3<br />

})<br />

}<br />

result 0 1 3 6<br />

GoalKicker.com – <strong>Angular</strong> 2 Notes for Professionals 144

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!