I have a session service like follows with two methods representing two ways of authenticating:
angular
.module('myApp')
.service('sessionService', SessionService);
function SessionService() {
var $ctrl = this;
this.logInTypeA = function(username, password, authenticator) {
...
}
this.logInTypeB = function(username, password, authenticator) {
...
}
...
}
I have a log in form component. I would like to have two instances of the form which use the two different log in methods but are otherwise the same:
<log-in-form log-in-method="$ctrl.sessionSerive.logInTypeA"></log-in-form>
<log-in-form log-in-method="$ctrl.sessionSerive.logInTypeB"></log-in-form>
The component's JS looks something like this:
angular
.module('myApp')
.component('logInForm', {
templateUrl: 'app/components/log-in-form.template.html',
controller: LogInFormController,
bindings: {
logInMethod: '&'
}
});
function LogInFormController() {
var $ctrl = this;
this.username = '';
this.password = '';
this.authenticator = '';
this.logIn = function() {
$ctrl.logInMethod($ctrl.username, $ctrl.password, $ctrl.authenticator);
};
...
}
However, I get an error when I try to run this:
TypeError: Cannot use 'in' operator to search for '$ctrl' in [email protected]
How do I pass a method in a service to a component?
Thanks in advance.