I've seen some examples where methods are added to the AngularJS controller as mixins. For example:
(function () {
var app = angular.module('angularjs-starter', []);
var ParentCtrl = function ($scope, $location) {
$scope.path = function () {
return $location.absUrl();
};
};
app.controller('ChildCtrl', function($scope, $injector) {
$injector.invoke(ParentCtrl, this, {$scope: $scope});
$scope.url = $scope.path();
});
})();
I want to be able to add new methods as a 'mixin' to a factory. How can I do that? It's not possible to pass $scope into a factory.
For example, the following doesn't work:
var serv = angular.module('myModule', [])
serv.factory('myService', ['$scope', '$injector', function ($scope, $injector) {
...