Comments (4)
Hi @reggieboyYEAH , thanks for pointing out the problem. I did a new major release (version 2.0.0) and now the angular service xdLocalStorage uses promises instead of ugly callbacks :).
I also moved the init function to the regular run because I needed it to resolve the iframe load promise.
I updated the docs so u can take a look in the new implementation. I hope it will help u. LMK otherwise.
from cross-domain-local-storage.
Hello @ofirdagan, first of all thanks for updating the framework 👍
But im still having issues, the iframe loads very late in the process causing undefined variables.
here is my code
var module = angular.module('app', ['xdLocalStorage'])
.config(function (xdLocalStorageProvider) {
}).run([
'xdLocalStorage', function(xdLocalStorage) {
console.log("Hello from app run");
xdLocalStorage.init(
{ /* required */
iframeUrl: 'http://localhost:58935/iframe.html'
}).then(function() {
//an option function to be called once the iframe was loaded and ready for action
console.log('Got iframe ready');
});
}
]).controller('IndexController', [
'xdLocalStorage', function(xdLocalStorage) {
console.log("Hello from index controller");
////xdLocalStorage.setItem('iframe', 'iframe');
xdLocalStorage.getItem('iframe').then(function(response) {
console.log(response.value);
});
}
]
);
and the output will be
Hello from app run index.js:18
Hello from index controller
angular.js:12116 TypeError: Cannot read property 'contentWindow' of undefined
at buildMessage (ng-xdLocalStorage.min.js:78)
at window.xdLocalStorage.window.xdLocalStorage.getItem (ng-xdLocalStorage.min.js:137)
at ng-xdLocalStorage.min.js:193
at angular.js:14347
at m.$get.m.$eval (angular.js:15574)
at m.$get.m.$digest (angular.js:15385)
at m.$get.m.$apply (angular.js:15679)
at angular.js:1582
at Object.e as invoke
at d (angular.js:1580)(anonymous function) @ angular.js:12116$get @ angular.js:8976(anonymous function) @ angular.js:14355$get.m.$eval @ angular.js:15574$get.m.$digest @ angular.js:15385$get.m.$apply @ angular.js:15679(anonymous function) @ angular.js:1582e @ angular.js:4379d @ angular.js:1580uc @ angular.js:1600Td @ angular.js:1494(anonymous function) @ angular.js:27867a @ angular.js:2927c @ angular.js:3201
index.js:12
Got iframe ready
It seems like an angular issue. The angular.run() does not wait for a promise to be resolved.
angular/angular.js#4003
i think the workaround is to bootstrap angular manually.
Not sure if there is a way that we can integrate that in the framework.
Do you have any recommendations?
I will try some approach and will let you know.
Cheers!
from cross-domain-local-storage.
Hey @reggieboyYEAH , I didn't know about this issue but a nice solution can be using the resolve option when u create IndexController. I'm guessing that u use routing of some sort.
Check out this video which explains it.
https://www.youtube.com/watch?v=Kr1qZ8Ik9G8&feature=player_embedded
I hope it helps :)
from cross-domain-local-storage.
Hi @ofirdagan, I tried the routing resolve approach but unfortunately it didn't work for me. It does not resolve values from xdlocalstorage.
I ended up using the deferred bootstrap approach.
https://github.com/philippd/angular-deferred-bootstrap
And now it works.
Thanks for the help! Appreciated :)
from cross-domain-local-storage.
Related Issues (20)
- Safari not setting cross domain localstorage HOT 8
- Problems with getItem HOT 4
- Restricting domain by origins
- Does not handle case where iframe fails to load HOT 2
- Cannot read property 'contentWindow' of undefined
- Angular2 version HOT 12
- Add browser support to Readme HOT 1
- Please publish in NPM registry HOT 1
- angular 2 support HOT 1
- On enabling this functionality in my extension, my script is executing multiple times
- Adding an inter-window communications mechanism HOT 2
- Works well in AngularJS but not in Angular 6 HOT 2
- Cannot read property 'contentWindow' of undefined
- A little help with Vue.js users HOT 1
- NOT work on mobile safari HOT 4
- Isn't this a huge security hole? HOT 8
- add mechanism to deal with exceptions
- permission mechanism
- Can not call methods of any angular service in the callback of any cross-domain-local-storage API HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cross-domain-local-storage.