Hi Yonatan,
It is a not good practice to make a service dependent on scope. That will
come back to you and will bite;)
And although my next sample will do the trick, I don’t like it too much
either. There might be reasons to to it
like this, but I don’t think this is something you should do without
serious thinking on the why the heck would I
need this to begin with.
To me, those are signs of an missing abstraction layer. For myself, I would
never go for an construct like this!
But if you insist on it, here is a way to do it:
(function () {
"use strict";
var MyApp = angular.module('myapp', ['kendo.directives']);
MyApp.controller('controller1', [
'$scope', 'NeededServices',
function ($scope, NeededServices) {
// here comes some logic for this scope which adds stuff to the
scope, like certain controller related variables
angular.extend($scope, NeededServices);
}
]);
MyApp.controller('controller2', [
'$scope', 'NeededServices',
function ($scope, NeededServices) {
// here comes some logic for this scope which adds stuff to the
scope, like certain controller related variables
angular.extend($scope, NeededServices);
}
]);
MyApp.service('NeededServices', [
"service1", "service2",
function (s1, s2) {
return {
service1: s1,
service2: s2
// an what other stuff you need across multiple controllers
};
}
]);
MyApp.service('service1', {
param1: 'someValue',
param2: 'someOtherValue',
param3: function () {
return "someValue";
}
});
MyApp.service('service2', {
param1: 'someValue',
param2: 'someOtherValue',
param3: function () {
return "someValue";
}
});
}());
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.