I am trying to develop a base controller in Typescript/Angular for accessing form data, but I'm encountering an issue where the form
member seems to be getting removed during compilation and is not present in the generated JavaScript code.
Could you please help me identify where I might be making a mistake?
Below is the snippet of my code:
export class FormController {
form: ng.IFormController;
constructor() {
}
showValidation(fieldName: string, errorType: string): boolean {
var field = this.form[fieldName];
var fieldError = typeof errorType === 'undefined' ? field.$invalid : field.$error[errorType];
return !field.$pristine && fieldError;
}
}}
export class ImplController extends FormController {
constructor(private $state: ng.ui.IStateService) {
super();
}
public validateField(): boolean {
return this.showValidation('field-name', 'invalid');
}
}
The resulting output in JS looks similar to this:
var FormController = (function () {
function FormController() {
}
FormController.prototype.showValidation = function (fieldName, errorType) {
...
};
return FormController;
}());