Skip to content

Instantly share code, notes, and snippets.

View paritosh64ce's full-sized avatar
🏠
Working from home

Paritosh paritosh64ce

🏠
Working from home
View GitHub Profile
@paritosh64ce
paritosh64ce / orderController.js
Last active November 12, 2017 14:11
Example - calling Angular1.x service from controller with/without headers
// controller function – calling service
$scope.loadOrders = function() {
orderService.loadOrder()
.then(function(result){
if(result) {
//populate $scope property for the view
}
})
}
@paritosh64ce
paritosh64ce / myAuthSvc.js
Last active November 12, 2017 10:51
Example - Angular 1.x controller calling data service which in turn calls custom common HTTP service
angular.module('myModule')
.service('myAuthSvc', ['$http', '$q', function($http, $q){
var loggedInUserDetails = null;
this.getLoggedInUserDetails = function(payload) {
var deferred = $q.defer();
if(loggedInUserDetails != null) { deferred.resolve(loggedInUserDetails); }
else{
$http.post('<loginURL>', /*payload for login*/)
.then(function(result){
loggedInUserDetails = result;
@paritosh64ce
paritosh64ce / calculator.component.ts
Last active April 19, 2018 17:05
TDD Angular component with Jasmine using @angular/cli
constructor(private mathSvc: MathService) { }
subtract() {
this.result = this.mathSvc.subtract(this.param1, this.param2);
}
@paritosh64ce
paritosh64ce / 1-math.service.ts
Created April 18, 2018 20:00
TDD Angular component with Jasmine using @angular/cli
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class MathService {
constructor() { }
subtract(a: number, b: number): number {