This is getting very very very annoying now... Im stuck on this for a long time... The problem is it is getting slow on loading.. This is my code i will explain at the bottom about it:
app.controller('chatCtrl', ["$scope", function($scope) {
var ref = new Firebase('MYFIREBASEAPP')
$scope.usernameProfile = ''
$scope.imageProfile = ''
ref.onAuth(function(authData) {
ref.child("Users Auth Info").child(authData.uid).on("value", function(snapshot) {
$scope.usernameProfile = snapshot.val().Username;
$scope.imageProfile = snapshot.val().Image
console.log(snapshot.val().Image)
console.log(snapshot.val())
console.log($scope.usernameProfile)
var username = $scope.usernameProfile
console.log($scope.imageProfile)
})
})
console.log($scope.usernameProfile)
console.log($scope.imageProfile)
}])
Here i am getting the usernameProfile and imageProfile from the data of the user... The problem here is that it loads wayyy to slow.. that when i try to render it to html by passing:
<img id="profileImage" ng-src="{{imageProfile }}" >
The image becomes blank.. for some reason the html dosent recognize the ng-model... also in my code above the ones at the bottom gets logged first then the others in the snapshot.val().. Please Please Help me.. Thankyou
EDIT
Tried this... still dosent work...
var ref = new Firebase('https://sparke.firebaseio.com/')
var syncObject = $firebaseObject(ref);
ref.onAuth(function(authData){
$scope.profile = $firebaseObject(ref.child('UsersAuthInfo').child(authData.uid).child("Image"));
$scope.profile.$loaded().then(function() {
console.log($scope.profile.$value);
$scope.imageProfile = $scope.profile.$value
});
})
EDIT
This dosent work:
ref.onAuth(function(authData) {
console.log("Good?)
ref.child("UsersAuthInfo").child(authData.uid).on("value", function(snapshot) {
$timeout(function() {
$scope.usernameProfile = snapshot.val().Username;
$scope.imageProfile = snapshot.val().Image
console.log(snapshot.val())
});
})
})
console.log($scope.usernameProfile)
The one at the first which says Good, gets executed first then the bottom one then the one inside .child()
EDIT3
Ok frank. Before i started, i just deleted the quotes and made it simpler...
Lets get started with the problem of $timeout...
So when i tested the $timeout for the original plunker(the simpler version...) It worked really fine This is the code:
ref.child('Image').on("value", function(snapshot) {
// tell AngularJS that we're going to make changes to $scope
$timeout(function(){
$scope.image = snapshot.val();
console.log(snapshot.val())
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
})
Now with the timeout when i tried to implement that to my original app it didnt work unforutunately for some reason... here is the code for that..:
ref.onAuth(function(authData){
ref.child("UsersAuthInfo").child(authData.uid).on("value", function(snapshot) {
// tell AngularJS that we're going to make changes to $scope
$timeout(function(){
$scope.imageProfile = snapshot.val().Image;
console.log(snapshot.val())
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
})
})
Now with the $firebaseObject...
The $firebaseObject didnt even work for my Simpler version of the plunker as when i put in this code:
$scope.image = $firebaseObject(ref.child('Image'));
It gave me a blank picture... meaning the default picture when the url is not right... And i have noticed that the problem with that is when i console.log() the $scope.image like this:
console.log($scope.image)
I get an object... not a value.. The object is like this:
$$conf: Object
$id: "Image"
$priority: null
$value: "http://png.clipart.me/graphics/thumbs/151/man-avatar-profile-picture-vector_151265384.jpg"
__proto__: Object
Help would be appreciated in either methods
EDIT 4:
Ok so now i managed to get the Image (The simple plunker i showed you) on the plunker... Here is the code for that:
var obj = $firebaseObject(ref);
obj.$loaded(
function(data) {
$scope.image = data.Image
},
function(error) {
console.error("Error:", error);
}
);
But again when i tried to do that on my actuall app im working on it still dosent work!!! This is my code on the app im working on...:
ref.onAuth(function(authData){
var obj = $firebaseObject(ref.child("UsersAuthInfo").child(authData.uid));
obj.$loaded(
function(data) {
$scope.imageProfile = data.Image
console.log(data.Image)
},
function(error) {
console.error("Error:", error);
}
);
})
Help would be appreciated!