Comments (5)
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.
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.
Take a look!
https://github.com/andyperlitch/angular-adhoc-module-loading-example
from angular-couch-potato.
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.
You got it! _.camelCase does take care of spacing
from angular-couch-potato.
Related Issues (20)
- testing HOT 22
- test issue
- Add http interceptor factory HOT 1
- Enter state after vendor library is loaded. HOT 25
- document registerConstant support HOT 4
- Lazy loaded directive is not applied on the controller's view HOT 1
- how to lazy load a controller whose name has a variable from the $stateParams in resolve's dummy?
- Add minify js file
- ready doesn't fire in angular 1.0.7? HOT 5
- super lazy : both html and js HOT 1
- Whether to support cmd?
- Add support for registerComponent
- sample ui-router example code is not work HOT 1
- Angular route with html5Mode giving 'Not found' page after reload in apache HOT 9
- AngularUI Router HOT 1
- where is server.js? HOT 1
- What about the documentation? HOT 2
- How to load the Main Controller? HOT 4
- Guidance on how to get Directives in 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 angular-couch-potato.