Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
@tkssharma
tkssharma / bootstrap.js
Created January 19, 2016 17:51
Creating HTTP angular Interceptor to intercept error from server side
/**
* Angular factory on HTTP interceptor
*/
(function() {
angular.module('Codefun')
.config(function ($httpProvider, $provide) {
$provide.factory('httpInterceptor', function ($q, $rootScope, AUTH_EVENTS) {
return {
'request': function (config) {
"use strict";
var path = require("path");
var Webpack = require("webpack");
// Our configuration
module.exports = {
// Define the entry point
entry: path.resolve(__dirname, "js", "app.js"),
@tkssharma
tkssharma / gist:830d612f47403ad639303ac80b8e2a3b
Created April 11, 2016 19:36
Hello World React Component
<html>
<head>
<script src="react.js"></script>
<script src="transformer.js"></script>
<title>My First React File</title>
</head>
<body>
<script type="text/jsx">
var HelloWorld = React.createClass({
render: function() {
@Component({
selector: 'search-product',
template:
`<div>
<input #prod>
<button (click)="findProduct(prod.value)">Find Product</button>
Product name: {{product.name}}
</div>
`
})
(function () {
// We keep these variables private inside this closure scope
var myGrades = [93, 95, 88, 0, 55, 91];
var average = function() {
var total = myGrades.reduce(function(accumulator, item) {
return accumulator + item}, 0);
return 'Your average grade is ' + total / myGrades.length + '.';
$rootScope.$safeApply = function($scope, fn) {
fn = fn || function() {};
if($scope.$$phase) {
//don't worry, the value gets set and AngularJS picks up on it...
fn();
}
else {
//this will fire to tell angularjs to notice that a change has happened
//if it is outside of it's own behaviour...
$scope.$apply(fn);
//be sure to inject $scope and $location somewhere before this
var changeLocation = function(url, force) {
//this will mark the URL change
$location.path(url); //use $location.path(url).replace() if you want to replace the location instead
$scope = $scope || angular.element(document).scope();
if(force || !$scope.$$phase) {
//this will kickstart angular if to notice the change
$scope.$apply();
}
@Component({
selector: 'search-product',
template:
`<div>
<input #prod>
<button (click)="findProduct(prod.value)">Find Product</button>
Product name: {{product.name}}
</div>
`
})
@Component({
providers: [ProductService]
})
class ProductComponent {
product: Product;
constructor(private productService: ProductService) {
this.product = this.productService.getProduct();
}
@Component({
selector: 'basic-routing',
template: `<a [routerLink]="['/Home']">Home</a>
<a [routerLink]="['/ProductDetail']">Product Details</a>
<router-outlet></router-outlet>`,
directives: [ ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: '/', component: HomeComponent, as: 'Home'},
{path: '/product', component: ProductDetailComponent, as: 'ProductDetail'}