I have the following situation, I use a jQuery preload plugin.
angular.module('app')
.factory('Preloader', function Preloader(Videos) {
return {
start: function() {
$.html5Loader({
filesToLoad: Videos.query(),
onBeforeLoad: function() {},
onComplete: function() {
//$scope.loaded = done
},
onElementLoaded: function(obj, elm) {},
onUpdate: function(percentage) {
//$scope.precentage = precentage
}
});
}
}
});
I build a factory where I wrap the plugin.
In my controller I have something like:
angular.module('playlist')
.controller('Ctrl', function($scope, Preloader, Videos) {
Preloader.start();
And on the HTML I have a loading screen which I want to hide with ng-if="!loaded".
Can someone explain me how to link the $scope.loaded from the factory to the $scope.loaded inside my controller?
$scopein Angular is always associated with an HTML view. Factories/services are not associated with any views, and therefore do not get a$scopeinjected into them like a controller would. Services/factories can have the$rootScopeinjected into them. You can put things on the$rootScopeor better use a directive like suggested above to access a specific$scope.