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

Entity Classes in Swift

We must admit that most of use MVC pattern when it comes to business kinda apps or any type of apps at all. And before developing on Ios i used entity classes with C#, Java, Python you name it, and i want to write an example of them in Swift let’s begin. Define a new Swift file I generally store my entity classes in a different folder like, Model or Entities....

2 min · Ahmet Gokdayi

Js, Property Descriptors

Sometimes you may want your variable to act like a constant variable or something, well we can achieve such a behaviour by using writable property descriptor Object Dot defineProperty Let’s see it in action, first we need an object; var b = {}; Then, let’s add a property to this objec,we can use the built-in defineProperty() function of the Object to achieve this : Object.defineProperty(b, "a", { value: "b letter", writable: false, configurable: true, enumerable: true }); b....

3 min · Ahmet Gokdayi

Swift Add UIViews programmatically

Recently, when i was working on a Swift project on Xcode, i added UITabBarController and run the project. When i opened back my storyboard, it was just gone. It threw an error, i tried to figure it out, tested some of the recommended fixes on google, but it could not be solved. Now, i’m 100% implementing my view controllers programmatically. Add a basic UIView I assume that you have just opened a new project and you have your ViewController....

3 min · Ahmet Gokdayi