ngoninit

Angular2 : Call method/ngoninit when parameter of route changes

橙三吉。 提交于 2021-02-18 12:09:41
问题 Right now I'm making a kind of web shop, and on my home page I've a dropdown of category Let say parent cat A, and sub cats B and C. Cat A, B and C are all represented by 1 component, CatAComponent. When I go in the first time in one of those cats, my ngoninit gets called and the pages displays what it needs to display. When I want to click on another sub cat, I'm still on the same component, but only a param of the route changes ( e.g. I was on localhost:123/CatA/CatB, now I'm on localhost

Angular2 : Call method/ngoninit when parameter of route changes

落爺英雄遲暮 提交于 2021-02-18 12:04:32
问题 Right now I'm making a kind of web shop, and on my home page I've a dropdown of category Let say parent cat A, and sub cats B and C. Cat A, B and C are all represented by 1 component, CatAComponent. When I go in the first time in one of those cats, my ngoninit gets called and the pages displays what it needs to display. When I want to click on another sub cat, I'm still on the same component, but only a param of the route changes ( e.g. I was on localhost:123/CatA/CatB, now I'm on localhost

Angular: function calling on constructor

一世执手 提交于 2021-01-28 08:21:48
问题 I'm following this auth0 tutorial, and it says there: The authentication service's handleAuth() method must be called in the app.component.ts constructor so it will run on initialization of our app: // src/app/app.component.ts import { AuthService } from './auth/auth.service'; ... constructor(private auth: AuthService) { // Check for authentication and handle if hash present auth.handleAuth(); } ... However, documentations and answers like this one say: Mostly we use ngOnInit for all the

Undefined varibale already declared whet getting data from api on ngOnInit

风格不统一 提交于 2020-05-17 06:36:31
问题 I'm trying to fetch data from nodeJS API with angular, I have a variable declared and I want to affect the response from server to it, here is my code : export class SondageSingleComponent implements OnInit, AfterViewInit { @ViewChild('containerPieChart') element: ElementRef; survey: any = {}; currentUser: any; statistics: any; colorCounter: any = 0; d3Colors: any[] = ["#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d"]; private host: D3.Selection; private svg: D3.Selection; private width:

Undefined varibale already declared whet getting data from api on ngOnInit

删除回忆录丶 提交于 2020-05-17 06:36:14
问题 I'm trying to fetch data from nodeJS API with angular, I have a variable declared and I want to affect the response from server to it, here is my code : export class SondageSingleComponent implements OnInit, AfterViewInit { @ViewChild('containerPieChart') element: ElementRef; survey: any = {}; currentUser: any; statistics: any; colorCounter: any = 0; d3Colors: any[] = ["#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d"]; private host: D3.Selection; private svg: D3.Selection; private width:

Why is ngOnInit called twice?

北慕城南 提交于 2020-01-08 16:22:09
问题 I trying to create new component, ResultComponent , but its ngOnInit() method is getting called twice and I don't know why this is happening. In the code, ResultComponent inherits @Input from the parent component mcq-component . Here is the code: Parent Component (MCQComponent) import { Component, OnInit } from '@angular/core'; @Component({ selector: 'mcq-component', template: ` <div *ngIf = 'isQuestionView'> ..... </div> <result-comp *ngIf = '!isQuestionView' [answers] = 'ansArray'><result

Is calling a function on ngOnInit async?

此生再无相见时 提交于 2019-12-21 11:04:22
问题 If I call a function in ngOnInit() that makes an observable call to get data, is the this.getSomething() call in ngOnInit still async or does ngOnInit wait until this.getSomething() returns a result? Basically does "doSomethingElse" get executed in ngOnInit() before or after this.getSomething() finishes? ngOnInit() { this.getSomething(); doSomethingElse; } getSomething() { this.someService.getData() .subscribe( result => { this.result = result; }, error => this.errorMessage = <any>error); }

Angular 4 ngOnInit not called after router.navigate

冷暖自知 提交于 2019-12-20 17:35:21
问题 I have 3 tabs in which one tab shows a table with list of employees. Works good when it is loaded the first time.ngOnInit Fetches data from server using http get. After that when I click add new employee to open a form, which take input from user and when that submit is clicked I call a function which calls the http post service to post that data to my server where it inserts the records and then after that it is redirected back to employee component, but now that employee component was

Angular 2 ngOnInit is not called when routerlink changes

橙三吉。 提交于 2019-12-19 04:04:43
问题 i have a menu bar that contain a list of menus loaded from express api and every menu is referenced to a page that have an alias wich will be the URL of that page i am trying to load the page when i click to menu, it's done but only when i refresh the page this my menu code export class MenuList implements OnInit { menus:Menu[]; menu:Menu; page:Page; constructor(private router:Router, private menuService:MenuService) { } getMenus():void { this.menuService.getMenus() .subscribe( menus => this

Angular 5 ngOnInit called more than once

早过忘川 提交于 2019-12-11 15:34:21
问题 I have component for choosing periods for some charts. It can be some absolute dates or some quick intervals (last 30 days and so on). Then if its less than 14 days you get data in 1 hour interval by default. If its more than 14 days you get 1 day interval (and cannot select 1 hour). The problem is when I choose some absolute date with less than 14 days - first I get data for 1 hour interval - that's ok - but then I want to change data to 1 day interval - at first I get them, but secondly