This file contains 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 greet() { | |
console.message('Hello World'); | |
} |
This file contains 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.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() { |
This file contains 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.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() | |
} | |
}]); |
This file contains 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.module('app').service('MyService', ['OtherService', function(OtherService){ | |
this.foo = function(){ | |
OtherService.goo(); | |
} | |
}]); |
This file contains 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 () { | |
function MyService(OtherService) { | |
this.foo = function () { | |
OtherService.goo(); | |
} | |
} | |
MyService.$inject = ['OtherService']; | |
angular.module('app').service('MyService', MyService); | |
})(); |
This file contains 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
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 |
This file contains 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 upperCaseDirective() { | |
return { | |
template: '<div>{{text}}</div>', | |
link: function (scope, elem, attrs) { | |
scope.text = attrs.text.toUpperCase(); | |
} | |
}; | |
} |
This file contains 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
beforeEach(inject(function($compile, $rootScope) { | |
element = angular.element("<div upper-case-attr text='Hello World'></div>"); | |
$compile(element)($rootScope); | |
$rootScope.$apply(); | |
})); |
This file contains 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
it("should be uppercase", function() { | |
expect(element.html()).toContain("HELLO WORLD"); | |
}); |
This file contains 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 upperCaseDirective() { | |
return { | |
template: '<div>{{text}}</div>', | |
link: function (scope, elem, attrs) { | |
scope.text = scope.text.toUpperCase(); | |
} | |
}; | |
} |
OlderNewer