Tic Tac Toe Game in Angular

This is a simple Tic Tac Toe game written in Angular 2. You can find the source code here Root Component The project is again generated by angular-cli. I did not include routing in the app. There is only a root component and an HTML & CSS file for it. I also did not touch index.html Logic Let’s have a look at our component, navigate to src/app/app.component.ts. We have predefined some of our data and also we have this constructor:...

March 17, 2017 · 3 min · Ahmet Gokdayi

Angular Injectable Services

When using AngularJS(1.xx), we were defining a service like this: var app = angular.module('app',[]); app.factory('customService',function($http){ return { getAll:function(){ return $http.get('Your_Api_Url_Here'); } } }); Well, why do we need to use services? If you don’t want to write more code and when you need to change your api, if you don’t want to change more code, angular services are your friend. Generally you’d make http requests but you can use these services for anything, for example if you want to communicate with other components in the app etc....

2 min · Ahmet Gokdayi

Consuming Angular Services

In my previous post, i talked about simple Angular Services. Now we’ll provide these services throughout our app and we’ll use their functions in a component. Let’s say we have this service named as sample.service.ts: import { Injectable } from '@angular/core'; @Injectable() export class SampleService{ private data : Array<any>; getUsers(){ if(this.data === null || this.data.length === 0) this.seed(); return this.data; } private seed(){ this.data = [ "Ahmet", "Murat", "John", "Jeffrey", "Benjamin" ]; } } And we want to consume this service, by invoking it from our component....

3 min · Ahmet Gokdayi