Skip to content

Instantly share code, notes, and snippets.

View ronapelbaum's full-sized avatar

Ron Apelbaum ronapelbaum

View GitHub Profile
@ronapelbaum
ronapelbaum / temp.js
Created July 4, 2016 20:07
javascript runtime error
function greet() {
console.message('Hello World');
}
@ronapelbaum
ronapelbaum / acd1.js
Last active July 4, 2016 20:14
angular Circular Dependency
angular.module("app", [])
.service('A', function(B) {
this.data1 = 'a';
this.foo = function() {
console.log('A.foo:', this.data1, B.data2);
}
})
.service('B', function(A) {
this.data2 = 'b';
this.foo = function() {
@ronapelbaum
ronapelbaum / ngModuleIssue.js
Created July 6, 2016 20:06
example of angular "modules" issue
angular.module('moduleA', []).service('ServiceA', function() {
this.getName = function() {
return 'bob';
}
});
angular.module('moduleB', []).service('ServiceB', ['ServiceA', function(ServiceA) {
this.greet = function() {
return 'Hello ' + ServiceA.getName()
}
}]);
@ronapelbaum
ronapelbaum / promise.test.js
Last active July 13, 2016 08:29
test an angular service with $promise
describe('GreetController spec', function() {
var mockService, deferred, ctrl;
beforeEach(module('MyModule'));
beforeEach(module(function($provide) {
//#1 - mock DataService
mockService = jasmine.createSpyObj('DataService', ['getGreeting']);
$provide.value('DataService', mockService);
}));
beforeEach(inject(function($controller) {
//#2 get an instance of the controller
function upperCaseDirective() {
return {
template: '<div>{{text}}</div>',
link: function (scope, elem, attrs) {
scope.text = attrs.text.toUpperCase();
}
};
}
beforeEach(inject(function($compile, $rootScope) {
element = angular.element("<div upper-case-attr text='Hello World'></div>");
$compile(element)($rootScope);
$rootScope.$apply();
}));
it("should be uppercase", function() {
expect(element.html()).toContain("HELLO WORLD");
});
@ronapelbaum
ronapelbaum / upperCase.directive.js
Created July 13, 2016 08:54
test a directive with scope
function upperCaseDirective() {
return {
template: '<div>{{text}}</div>',
link: function (scope, elem, attrs) {
scope.text = scope.text.toUpperCase();
}
};
}
@ronapelbaum
ronapelbaum / upperCase.directive.test.js
Created July 13, 2016 08:56
test a directive with scope
beforeEach(inject(function($compile, $rootScope) {
scope = $rootScope.$new();
scope.text = 'Hello World';
element = angular.element("<div upper-case-scope text='text'></div>");
$compile(element)(scope);
scope.$apply();
}));
@ronapelbaum
ronapelbaum / acd.js
Created July 19, 2016 07:11
angular circular dependency
angular.module("app", [])
.service('A', function(B) {
this.data1 = 'a';
this.foo = function() {
console.log('A.foo:', this.data1, B.data2);
}
})
.service('B', function(A) {
this.data2 = 'b';
this.foo = function() {