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 / MyService.js
Last active August 7, 2016 17:26
improve your angular 1.x code style (1)
angular.module('app').service('MyService', ['OtherService', function(OtherService){
this.foo = function(){
OtherService.goo();
}
}]);
@ronapelbaum
ronapelbaum / MyService.js
Last active August 7, 2016 17:26
improve your angular 1.x code style (3)
(function () {
function MyService(OtherService) {
this.foo = function () {
OtherService.goo();
}
}
MyService.$inject = ['OtherService'];
angular.module('app').service('MyService', MyService);
})();
@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();
}
};
}