/**
* @param {!angular.$http} $http The Angular http service.
* @constructor
*/
hello.request.Request = function($http) {
/** @type {!angular.$http} */
this.http_ = $http;
};
hello.request.Request.prototype.get = function() {/*...*/};I've been wondering about the same.
It seems to me that a type is missing for that in the angular-1.3.js externs file.
There should be a @typedef looking like this:
/**
* @typedef {{$get: (Function|Array.<(string|Function)>)}}
*/
angular.ServiceProvider;
With this we'd be able to declare a service provider like this:
/**
* @return {angular.ServiceProvider}
*/
app.createMyServiceProvider = function() {
return {
$get: function() {
// ...
return myService;
}
};
};
module.provider('myService', app.createMyServiceProvider);
Does it make any sense?
goog.provide('app.MyService');
goog.provide('app.MyServiceProvider');
/**
* MyServiceProvider
* @constructor
* @export
*/
app.MyServiceProvider = function() {
/** @type {string} */
var defaultPath = "/foo";
/**
* MyService definition
* @param {!angular.$http} $http The Angular HTTP Service.
* @constructor
* @ngInject
*/
app.MyService = function($http) {
this.http_ = $http;
};
/**
* Do Something
* @return {!angular.$q.Promise} Promise containing the response.
* @export
*/
app.MyService.prototype.doSomething = function() {
return this.http_.get(defaultPath);
};
/**
* Sets the default path
* @param {string} path The default path.
* @export
*/
this.setDefaultPath = function(path) {
defaultPath = path;
};
/**
* Returns an instance of MyService
* @return {!app.MyService}
* @export
*/
this.$get = app.MyService;
};
Using @export for $get may be a good idea, and we may actually not need a new extern declaration at all!
How about the following?
goog.provide('app.MyService');
goog.provide('app.MyServiceProvider');
/**
* @constructor
* @export
*/
app.MyService = function() {
// ...
};
/**
*/
app.MyService.prototype.doSmthg() {
// ..
};
/**
* @constructor
* @export
*/
app.MyServiceProvider = function() {
// ...
};
/**
* @export
* @ngInject
*/
app.MyServiceProvider.prototype.$get = function($http) {
var service = new app.MyService();
// ...
return service;
};
module.provider('MyService', function() {
return new app.MyServiceProvider();
});
This is untested.