I am facing an issue with my directive.
export class SigninFormDirective implements angular.IDirective {
// setting up the directive
restrict: string = 'AE';
templateUrl: string = "/public/app/signin/views/directiveTemplates/signinForm.html";
scope: Object = { formData: "=" };
controller: Function = SigninDirectiveCtrl;
controllerAs: string = "form";
bindToController: boolean = true;
constructor($http: angular.IHttpService, $q: angular.IQService) {
}
static SignupFormFactory(): angular.IDirectiveFactory {
const directive = ($http: angular.IHttpService, $q: angular.IQService) => {
return new SigninFormDirective($http, $q);
};
directive.$inject = ['$http', '$q'];
return directive;
}
}
I need to access the formData
variable in the directive controller. This variable is passed from the parent controller.
// defining the main controller`
export class SigninCtrl implements interfaces.ISigninCtrl {
formData: Object[];
// assigning an IID for MainController
static IID = "SigninCtrl";
// defining the controller
constructor(public $state : angular.ui.IState) {
this.init();
}
private init = () => {
this.formData = [];
}
}
In the directive's controller, I have a method where I'm trying to access the formData:
public submitForm($event: angular.IAngularEvent, email: string, password: string) {
var userService = this.userService;
var utilityService = this.utilityService;
// form submission
this.formWasSubmitted();
if(typeof password === undefined) {
return;
} else {
var deferred = this.$q.defer();
userService.signin(email, password)
.then(dataObject => {
if(dataObject.data.status.short === "NOTACTIVATED") {
this.formData.push(dataObject);
deferred.resolve(dataObject);
}
}, error => {
deferred.reject(error);
})
}
}
I am utilizing controllerAs
- how can I access formData
within the directive controller? I have set up the two-way binding, but I am unsure how to access it in the controller using controllerAs
. Do I need to use $scope
? Or is there another way to achieve this? Currently, I am encountering this error:
https://i.sstatic.net/hUtYh.png
Any assistance would be greatly appreciated. Thank you!