I am working on a small application in angularjs :-
I am working on deleting a contact. Everything works fine but the this.openModal() throws an error as undefined even though it is defined in the same JS.
Have some confusions on how to use this and $scope together. Can anyone help ?
$scope.deleteContact = function ()
{
var delNo = $scope.contactNumber;
var delName = $scope.contactName;
var person = {};
person['phone'] = delNo;
...
...
$timeout(function(){
delete $scope.contacts[person['phone']];
});
$scope.activeChats={};
$scope.showContactName = false;
this.openModal();
console.log("Delete success");
}
EDIT:
this.openModal is a function I have defined as follows
this.openModal = function (input) {
this.modalOpen = !this.modalOpen;
// RESET
this.showNewMessage = false;
this.showEditGroup = false;
this.showAddContact = false;
this.showPersonSettings = false;
this.showUserProfile = false;
if (input == "newmessage"){
this.showNewMessage = true;
} else if (input == "showEditGroup"){
this.showEditGroup = true;
} else if (input == "newcontact"){
this.showAddContact = true;
} else if (input == "userprofile"){
this.showUserProfile = true;
} else if (input == "usersettings"){
this.showPersonSettings = true;
}
}
openModal()defined exactly? What do you thinkthisrefers to? Also: this doesn't sound like the angular way to approach this task.this.openModal()defined?