There are some useful libraries I want to use in angularjs, e.g. jquery, underscore, underscore.string.
It might not be a good idea to use them directly in angular code(say, controllers, directives), because it's hard to mock and test. So I want to wrap them into angular modules:
angularUnderscore.js
define(['angular', 'underscore'], function(ng, _) {
return ng.module('3rd-libraries')
.service('underscoreService', function() {
return _;
});
});
My questions are:
- Is it good to use
.service()
to define aservice
? Or is a factory or constant better? - Is it good to use
underscoreService
, or justunderscore
is enough and better?