This article mainly introduces the Angularjs module management Problem of unconventional processing method, is a helpless, to share to the small partners, we can refer to.
1. Causes
Oneself has been doing winform, fortunately from a big God hand picked up a node.js,express,angularjs, such as a set of many open source framework of a project, spot, so while learning, while using their previous thinking to organize, refactoring code;
2. The question
In some environment, need to use bootstrap modal frame, we are learning win? It's natural to think of the boosstrp modal box as a universal thing, calling around ...
Then use Patial to refer to the dialog box file, the dialog itself with Anglurjs for server-related communication.
It turns out that when you use only one, it works, and if you refer to it multiple times (call different data), there's only one.
3. Analysis
Check some information to understand, angular.bootstrap this call on the page can only be executed once, more than the implementation is not used, and I will have all angular.module written in a separate JS file, each JS file finally called the Angular.bootstrap So, the natural will hang out;
4. Looks forward to
So, want to have a solution mechanism, let me partial all kinds of files to the page, and JS file will not duplicate the reference, Angulurjs can also be perfect implementation;
5. Address
Pro-although this way a bit disgusting, but absolutely directly effective;
The idea is to dynamically maintain all the ANGULARJS modules in a global array and then load them dynamically.
No, put the code.
On frames page (layout ...) The head refers to the Angulurinit.js file with the following code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13-14 |
Array.prototype.indexOf = function (val) {for (var i = 0; i < this.length. i++) {if (this[i] = val) return i;} retur n-1; }; var jsmodules = new Array (); Function Confirm (val) {if (Jsmodules.indexof (val) > 1) return; else Jsmodules.push (Val); }; |
Each of the Anglur.js modules
The code is as follows:
Angular.bootstrap (document, [ModuleName]);
Replace into
The code is as follows:
Confirm (ModuleName);
In Layout (Layout page? I don't know what it is, anyway. The common frames page) the tail is added to the Angulur.js file, the code is as follows:
The code is as follows:
(function () {
var app = Angular.module (' app ', jsmodules);
Angular.bootstrap (document, [' app ']);
})();
The above mentioned is the entire content of this article, I hope you can enjoy.