This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'search-product', | |
template: | |
`<div> | |
<input #prod> | |
<button (click)="findProduct(prod.value)">Find Product</button> | |
Product name: {{product.name}} | |
</div> | |
` | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 + '.'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'search-product', | |
template: | |
`<div> | |
<input #prod> | |
<button (click)="findProduct(prod.value)">Find Product</button> | |
Product name: {{product.name}} | |
</div> | |
` | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
providers: [ProductService] | |
}) | |
class ProductComponent { | |
product: Product; | |
constructor(private productService: ProductService) { | |
this.product = this.productService.getProduct(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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'} |
OlderNewer