if you need to assign to variables outside angular/ionic control, we need to use $apply function.
$scope.$apply(function() {
$scope.myFiles = userfiles;
$scope.myFilesLength = $scope.myFiles.length;
});
this scenario came when i am doing the assignment in an callback function.
var AppControllers = angular.module('starter.controllers');
AppControllers
.controller('DownloadsPageCtrl',function($scope,$state,LDPServices,$cordovaDevice){
//alert("in before enter downloads");
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(fileSystem){
var FileStoredLoc = fileSystem.root.toURL()+"/LP/";
var dirEntry = fileSystem.root.getDirectory("LP",{create:true},gotDir);//fileSystem.root;
}
}
function gotDir(dirEntry){
//alert("direntry"+dirEntry);
var dirReader = dirEntry.createReader();
//alert("dirreader"+dirReader.readEntries);
dirReader.readEntries(success,fail);
}
function success(entries){
//alert("succ:"+entries.length);
//var AppDir = FileStoredLoc;//fileSystem.root.toURL()+"/LP/";
var userfiles=[];
for( i=0;i<entries.length;i++)
{
userfiles.push(entries[i].name);
}
//alert(userfiles.length);
try
{
//var myf=["a.1","b.2"];
//alert("b4");
$scope.$apply(function() {
$scope.myFiles = userfiles;
$scope.myFilesLength = $scope.myFiles.length;
});
//alert("after");
}
catch(excp)
{
$ionicPopup.alert({
template: "Unable to open File" ,
okType:'button-positive'
});
}
}
html:
<ul class="list">
<li ng-repeat="File in myFiles" class="item" ng-click="openFile(File)" ng-if="File != '.DS_Store'">
{{File}}
</li>
<div align="center" ng-if="myFilesLength == 0" style="color:white">
NO FILES TO BE SHOWN
</div>
</ul>
$scope.$apply(function() {
$scope.myFiles = userfiles;
$scope.myFilesLength = $scope.myFiles.length;
});
this scenario came when i am doing the assignment in an callback function.
var AppControllers = angular.module('starter.controllers');
AppControllers
.controller('DownloadsPageCtrl',function($scope,$state,LDPServices,$cordovaDevice){
//alert("in before enter downloads");
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(fileSystem){
var FileStoredLoc = fileSystem.root.toURL()+"/LP/";
var dirEntry = fileSystem.root.getDirectory("LP",{create:true},gotDir);//fileSystem.root;
}
}
function gotDir(dirEntry){
//alert("direntry"+dirEntry);
var dirReader = dirEntry.createReader();
//alert("dirreader"+dirReader.readEntries);
dirReader.readEntries(success,fail);
}
function success(entries){
//alert("succ:"+entries.length);
//var AppDir = FileStoredLoc;//fileSystem.root.toURL()+"/LP/";
var userfiles=[];
for( i=0;i<entries.length;i++)
{
userfiles.push(entries[i].name);
}
//alert(userfiles.length);
try
{
//var myf=["a.1","b.2"];
//alert("b4");
$scope.$apply(function() {
$scope.myFiles = userfiles;
$scope.myFilesLength = $scope.myFiles.length;
});
//alert("after");
}
catch(excp)
{
$ionicPopup.alert({
template: "Unable to open File" ,
okType:'button-positive'
});
}
}
html:
<ul class="list">
<li ng-repeat="File in myFiles" class="item" ng-click="openFile(File)" ng-if="File != '.DS_Store'">
{{File}}
</li>
<div align="center" ng-if="myFilesLength == 0" style="color:white">
NO FILES TO BE SHOWN
</div>
</ul>
No comments:
Post a Comment