我想在启动/初始化angular4 AppModule之前调用API。这有可能吗?
import * as mongoose from "mongoose";
(<any>mongoose).Promise = global.Promise;
let cacheDb: mongoose.Connection = null;
export let connect = () => {
if (cacheDb && mongoose.connection.readyState === 1) {
return cacheDb;
} else {
// Mongoose config and setting global Promise
mongoose.connect(process.env.MONGODB_URI, {
promiseLibrary: global.Promise,
connectTimeoutMS: 20 * 1000
}).then(() => {
cacheDb = mongoose.connection;
return cacheDb;
}).catch((err) => {
console.log(err);
});
}
};
export let disconnect = () => {
mongoose.disconnect();
}
在初始化bootstrap组件'AppComponent'之前,我想调用一个API。