I'm having some checkboxes in my component which is inside a @for directive for rendering according to data size. I have a function to retrieve the array which used inside the for directive as following,
getMenuList() {
let apiResp = this.services.getMenus()
apiResp.subscribe((resp:any)=>{
this.menuList = resp
if (this.menuList.response === 'success') {
let apiresponse = JSON.stringify(this.menuList)
let apiresponsefinal = JSON.parse(apiresponse)
for (let index = 0; index < apiresponsefinal.ug_details.length; index++) {
const element = apiresponsefinal.ug_details[index];
let menuitem:dropLists = {dropid:element.menu_id,dropname:element.menu_name}
this.menuValues.push(menuitem)
}
}
})
}
services is my API calling service as following,
getMenus():Observable<any>{
return this.http.get('http://localhost:234/jeevadhara/api/v1/getmenus',{headers:{'auth_value':secret.auth_value}})
}
As I'm using parent and child component based routing, components were loaded inside a div of parent component. Due to this child component is not refreshing the page, hence when I put the function calling in ngOnInit(), it will only trigger when I refresh the page.
How to call the function or define menuValues with proper values by calling services?