I have an angular
application, written in typescript
whose config
registration was just getting out of control, and huge - it took up about 3 pages.
So I broke it up into multiple config(fn)
sections, and moved as much logic out of that page as I could and encapsulated specific behaviors into their own classes; it seemed like the smart way to go about cleaning it up.
each of the new classes looks something like this;
namespace config {
export class http {
constructor($httpProvider: ng.IHttpProvider){
// $httpProvider configuration
}
}
}
so back in my main.ts
, the file that creates my module
and registers everything, I import them over.
import { http } from './config/http';
import { router } from ./config/router';
// etc.
but the namespace doesn't seem to be a part of this. I cannot call them such as...
config(config.http)
config(config.router)
// etc.
I've had to instead give them new alias when bringing them in;
import { http as configHttp } from './config/http';
import { router as configRouter } from './config/router';
// etc.
Why is this? Is there anything I can do to keep the namespace definition intact and use the simpler method I was aiming for?
The namespace you have is redundant if you're using import statements.
Here:
import { http } from './config/http';
You're asking only for the http class in that file so that's what you're getting.
Also, if anything it should be module config
and not namespace config
.
You should read Namespaces and Modules and more precisely Needless Namespacing .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.