After implementing ng-if
in my code, I observed two specific instances where it caused unexpected behavior. The first instance involves using ng-if="isOwnProfile" for an image-upload toolbar.
However, the use of ng-if
resulted in the event listener ceasing to work as expected. Here is a snippet of the code:
$scope.myOwnProfile = false;
if (userLoggedIn === userUID) {
console.log('my images');
$scope.myOwnProfile = true;
} else {
console.log('not my images');
}
$("#image-upload").change(function(e) {
$scope.myOwnProfile = true;
var file = e.target.files[0];
var imageRef = firebase.storage().ref...
This issue also arises when trying to add a message to the page and Firebase. Here's an example of the code:
$scope.addMessage = function(){
var date = new Date();
$scope.messages.$add({
timestamp: (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear(),
from: $scope.visitorRealName.name,
content: $scope.message
});
$scope.message = '';
};
Upon investigating further, I received an error message from Firebase stating "Key content was undefined. Cannot pass undefined in JSON. Use null instead". This error occurs due to the presence of ng-if in my HTML code.
I am puzzled as to why utilizing ng-if triggers these issues. My intention was to set the user's profile to true based on whether they are a friend or if it's their own profile, hence the modification of $scope variable.