Coder Social home page Coder Social logo

AngularJS - xdLocalStorageProvider.init() is called after the module.run() and controller initialize about cross-domain-local-storage HOT 4 CLOSED

ofirdagan avatar ofirdagan commented on July 21, 2024
AngularJS - xdLocalStorageProvider.init() is called after the module.run() and controller initialize

from cross-domain-local-storage.

Comments (4)

ofirdagan avatar ofirdagan commented on July 21, 2024

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.

reggiepangilinan avatar reggiepangilinan commented on July 21, 2024

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.

ofirdagan avatar ofirdagan commented on July 21, 2024

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.

reggiepangilinan avatar reggiepangilinan commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.