IONIC - can't access externalDataDirectory on $ionicView.enter - javascript

I'm trying to read a directory to check how many files exists
When I open the app I get this error
ionic.bundle.js:26799 TypeError: Cannot read property
'externalDataDirectory' of undefined
But when I go to another view, and came back, this works fine.
I try to call the same function on
$ionicPlatform.ready and works, but this way is executable only once, I need to call every time I enter on this page.
Anyone had this error before?
I'm using ionic v1 and $cordovaFile extension
Thank you

Wrap your code with $ionicPlatform.ready:
$scope.$on('$ionicView.enter', function() {
$ionicPlatform.ready(function() {
// cordova file code
});
});

Related

Add "update available, please refresh" prompt to PWABuilder Cache-first service worker

I'm making my website offline first with service worker. I want to prompt user to refresh the page when updated content is available. I want users to know that they are viewing outdated contend, so they can get latest content by refreshing the page.
These implementations are a good example:
Service worker demo by Mozilla
Approach #3 in this article.
I am using cache-first service worker provided by PWABuilder. It works well, but it does not prompt the user of available updates.
I have tried to copy the code from the articles above, but couldn't get it to work.
Here is the repo of the service worker I currently use.
The code I am trying to add to the service worker script:
addEventListener('message', messageEvent => {
if (messageEvent.data === 'skipWaiting') return skipWaiting();
});
Script I'm trying to add to the webpage:
/ reload once when the new Service Worker starts activating
var refreshing;
navigator.serviceWorker.addEventListener('controllerchange',
function() {
if (refreshing) return;
refreshing = true;
window.location.reload();
}
);
function promptUserToRefresh(reg) {
// this is just an example
// don't use window.confirm in real life; it's terrible
if (window.confirm("New version available! OK to refresh?")) {
reg.waiting.postMessage('skipWaiting');
}
}
listenForWaitingServiceWorker(reg, promptUserToRefresh);
If I just add this code to service worker and webpage respectfully, the service worker functions fine. But update prompt does not work.
I get this error in console:
Uncaught ReferenceError: reg is not defined
at (index):231
Well, your problem doesn't necessarily have that much to do with Service Workers :) If you look at the error message (shown in console) carefully, you'll see that it is clearly telling you a variable called reg is not defined. In other words, somewhere in your code you're trying to reference a variable with a name "reg" but "reg" doesn't exist there.
It seems that the code pasted in your question is not the whole thing, but I suspect the problem lies here:
listenForWaitingServiceWorker(reg, promptUserToRefresh);
Anyhow, the error message tells you the problem occurs at line 231 in your html file so check that out.

loadJSON not Defined - Chrome Extension Error

I'm incredibly new to HTML/Javascript/API's and im trying to make my first chrome extension using coinmarketcaps' public API.
API: https://api.coinmarketcap.com/v2/ticker/?limit=12&sort=rank&convert=ETH
My Code:
console.log("Running");
function setup() {
loadJSON('https://api.coinmarketcap.com/v2/ticker/?
limit=12&sort=rank&convert=ETH', gotData, 'jsonp');
}
setup();
function gotData(data){
console.log(data);
list = data;
}
gotData();
Essentially what I want to do is load in the data and then print the data to my console to make sure that it is in fact loaded. The error that I'm getting when i check the background.js console after uploading the extension is 'loadJSON is not defined'
I don't know if im missing a package or am unable to use such a command but after looking online for a while I can't seem to figure it out. Another thought that I had was maybe it can't be used in a background.js file. Also, I am using Atom software for this project. Let me know if you need any more information, any help is appreciated.

AngularJS mysterious error

I can't for my live figure out why Angular is not working along.
I defined a simple app and controller:
angular.module('weatherApp', [])
.controller("weatherController", function() {
console.log('weather controller created!');
});
In my HTML I have:
<div ng-app="weatherApp" ng-controller="weatherController"></div>
Nothing else. I'm using AngularJS 1.2.28 (constrained by the project I'm working with). Upon loading of the page, my console logs the expected text above. However, immediately following it is the following error:
Error: [ng:areq] http://errors.angularjs.org/1.2.28/ng/areq?p0=weatherController&p1=not%20a%20function%2C%20got%20undefined
Why is it doing this when it's (apparantly) working just fine?
When I'm not using a module or controller and simply define a global weatherController function, everything again works just fine.
I've looked around, but can't find anything about this being specific to 1.2.28 or something.
I figured it out! Apparently the ClientDependency was loading another app.js which does a lot more with AngularJS than my simple controller. The two simply couldn't co-exist!
Since I didn't need the other app in this particular page, I excluded it from the ClientDependency and voilá, fixed!

Meteor: disable hot code push

I'm developing a phonegap app and hot code push is causing a problem for some of my users (after push, app hangs and users have to re-install the new app).
I'd like to disable hot code pushes and found the following snippet but am getting the error, "TypeError: Cannot call method 'onMigrate' of undefined"
Meteor._reload.onMigrate(function() {
return [false];
});
Looks like the _reload object is only available on the client. I moved the snippet of code to a client directory and that solved it.
Leaving this question / answer here for anyone else who might come across it.
You can set the environment variable AUTOUPDATE_VERSION to something static. You need to set this environment variable when you build your app and when you start the server. (Source)

Sencha build error when viewed in browser

I have finally managed to create a production build of my sencha web app using Cmd 3.10.2.342 and touch 2.2.1
All my bespoke files are included and deltas are created as one would expect. However, when I run it in the browser, it stalls at the loading view. Console log says:
TypeError: 'undefined' is not a function (evaluating 'h.call(w,w)')
I have traced the error to Ext.application({... in app.js.
I have tried the following changes, but still get errors:
new Ext.application({...
Ext.Application({...
new Ext.Application({...
How can I rectify this?
When I generate an apk file, I do not have this problem
In my production app.js, I found this
if(!s){a.set(i,w);if(h){h.call(w,w)}a.triggerCreated(i);return}
I don't really know what it does. I have tried deleting it etc, but it just the gives other errors instead
I traced this back to issues/conflicts with itemId and id where sencha was telling me that a component already existed and should be destroyed.
Solved it by removing id and itemId and used cls instead

Categories

Resources