Coder Social home page Coder Social logo

Comments (5)

laurelnaiad avatar laurelnaiad commented on June 12, 2024

To answer the easy question, yes -- any time you want to load a couch-potato component(s) file, you'll need require.js.

Hmm. I think what I had in mind with the promised-and-undelivered "ad-hoc" docs was just that you can, at any time, put a couch-potato file into a require.js require function's dependencies list. When you do that, then, by the time the file is asynchronously loaded and a digest cycle starts and completes, the component(s) that are defined in said file will be defined to angular.

The thing to keep in mind, though, is when you do this, you are too late for the digest cycle in which that file was loaded. The reason it "just works" in the routing scenario is that you get a fresh "free-to-you" digest cycle as the view and the controller are instantiated.

So, when you don't do the loading in that context, you almost have to "foresee" the need for the dependency in order to have it available in time. I can't think of a good reason why you would really want to do this, unless you are avoiding angular routing (be it ui-router or ngRouter) altogether, in which case you are probably not really going to be worried about couch-potato, because you'll probably end up reloading your entire app as the user navigates around.

Can you tell me what you were thinking you might have benefitted from in this not-well-described scenario?

from angular-couch-potato.

andyperlitch avatar andyperlitch commented on June 12, 2024

Good news! I actually was able to get a working example of what I want to do and it doesn't need require.js. Here's the gist of my use-case: I want to dynamically load a module containing a directive, and (optionally) services that the directive depends on. Once loaded, I want to create an element with that directive and inject it into the page. All this should happen when the user performs some action. I am going to create a repository with my working example soon, so I will link to it here.

from angular-couch-potato.

andyperlitch avatar andyperlitch commented on June 12, 2024

Take a look!
https://github.com/andyperlitch/angular-adhoc-module-loading-example

from angular-couch-potato.

laurelnaiad avatar laurelnaiad commented on June 12, 2024

That's a fascinating application of it.... thanks for sharing!

I wonder why this works, though....

  var couchPotatoMethod = _.camelCase('register ' + componentType);
          // Use couchPotato to add it to our module
          $couchPotato[couchPotatoMethod](componentArguments);

Note the space between register and the closing '...

Perhaps camelCase takes care of spaces? I only knew about dedasherization.

from angular-couch-potato.

andyperlitch avatar andyperlitch commented on June 12, 2024

You got it! _.camelCase does take care of spacing

from angular-couch-potato.

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.