Skip to content

Instantly share code, notes, and snippets.

@Bolza
Bolza / pubSub.js
Last active December 23, 2015 14:45
//`first` reads the data from the service
Controller first (myService) ->
this.firstValue = myService.get().firstValue //using a getter so there's no direct reference
myService.onChange(function(newData) {
this.firstValue = newData.firstValue
})
//`second` sets the data inside the service
@Bolza
Bolza / myrepeat.js
Created October 15, 2015 10:14
Wraps ng-repeat
app.controller('MainCtrl', function($scope) {
$scope.numbers=[1,2,3,4,5,6];
});
app.directive('myRepeat', function($compile){
return {
//High priority means it will execute first
priority: 5000,
//Terminal prevents compilation of any other directive on first pass
terminal: true,
@Bolza
Bolza / envConfig.provider.js
Created June 9, 2015 13:14
Attempt to make config loading syncronous in AngularJS
(function() {
'use strict';
var envconfig = angular.module('app.envConfig', []);
envconfig.config(confFunc);
envconfig.provider('startup', startupFactory);
confFunc.$inject = ['startupProvider'];
/* @ngInject */
function confFunc(startupProvider) {
@Bolza
Bolza / ng-test-directive-model.js
Last active August 29, 2015 14:16
AngularJS Test: Directive with ngModel
/* jshint -W117, -W030 */
describe('LineItemType', function() {
var scope, compileDirective, spy;
beforeEach(module('app.lineItem', function($provide) {
$provide.service('lineItemType', mockData.lineItemTypeService());
}));
beforeEach(inject(function($injector) {
var $controller = $injector.get('$controller');
@Bolza
Bolza / tr.js
Created March 9, 2015 18:03
AngularJS Test: Testing Routes
beforeEach(module('app', function($stateProvider) {
$stateProvider.state('default', {
url: '/',
});
}));
@Bolza
Bolza / gist:b768da0828acfea2100f
Last active August 29, 2015 14:12
Angular Service, Provider, Factory Quick Sintax
// from http://jsfiddle.net/thomporter/zjFp4/1/
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
};
});