As a beginner in AngularJS (just diving in this week), I've encountered an issue with a checkbox input connected to an ng-change event.
<input type="checkbox" ng-model="vm.hasCondoKey" ng-change="vm.onKeyCheckboxChange()" />
The ng-change event triggers the execution of the "onKeyCheckBoxChange" function in the controller.
export class CondoKeyController {
public condoKey: AdditionalItemModel;
public additionalItems: AdditionalItemModel[];
public hasCondoKey: boolean = false;
static $inject = ["$scope","CondoKeyService"];
constructor($scope: any, CondoKeyService: ICondoKeyService) {
// Some initialization logic here
}
public onKeyCheckboxChange(): void {
console.log("Checkbox changed.");
if(this.hasCondoKey === true) {
// Handling of condoKey logic
} else {
// Resetting condoKey quantity
}
}
}
The "CondoKeyController" receives the array "additionalItems" from a parent component via a directive. While some variables can be accessed within the "onKeyCheckBoxChange" function, others like "this.condoKey" and "this.additionalItems" pose a challenge.
I'm puzzled by the ability to access certain variables but not others in the function. Any insights on why this is happening and how to overcome it?
If you have a clue on why I can't access all variables or how to rectify this issue, please share your thoughts.
Angularjs 1.6.6 Typescript ~2.3.1