Answer the question
In order to leave comments, you need to log in
How to correctly request data at the time of ngOnInit?
Greetings, I have such a problem ... At the time of page initialization, I have requests to the server. I am using express and sequelize. I looked at the courses and everything seems to be ok. But they didn't explain how to make multiple queries. Here is my code:
This is a router in which the getArrSelectDataType, getArrSelectTicker, getArrSelectSource functions are called.
Everything is ok. In this case, I have one get function and two post methods.
const express = require('express');
const controller = require('../controllers/data_table')
const router = express.Router();
router.get('/', controller.getArrSelectDataType);
router.post('/', controller.getArrSelectTicker);
router.post('/', controller.getArrSelectSource);
module.exports = router;
const Data_table = require('../models/Data_table');
console.log('11ssssssssss')
module.exports.getArrSelectDataType = async (req, res) => {
console.log('dddddddddddd')
const group_name = await Data_table.findAll({
attributes: ['group_name'],
group: 'group_name'
})
const arrSimple = group_name.map(el => {
return el.group_name
});
res.json({
arrSimple
})
}
module.exports.getArrSelectTicker = async (req, res) => {
console.log('hhhhhhhhhhh')
const value = await Data_table.findAll({
attributes: ['value'],
group: 'value'
});
const arrValue = value.map(el => {
return el.value
});
res.json({
arrValue
})
}
module.exports.getArrSelectSource = async (req, res) => {
console.log('eeeeeeeeeee')
const source = await Data_table.findAll({
attributes: ['source'],
group: 'source'
})
const arrSource = source.map(el => {
return el
});
res.json({
arrSource
})
}
Answer the question
In order to leave comments, you need to log in
Your routes are the same:
router.get('/', controller.getArrSelectDataType);
router.post('/', controller.getArrSelectTicker);
router.post('/', controller.getArrSelectSource);
router.get('/get-arr-select-data-type', controller.getArrSelectDataType);
router.post('/get-arr-select-data-ticker', controller.getArrSelectTicker);
router.post('/get-arr-select-data-source', controller.getArrSelectSource);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question