Component instances have a life cycle that we can hook into. Currently, our mini application contains four components: App
, accordion
, accordion-tab
, and user-info
, but a typical Angular application will contain tens of component trees that Angular will create, update, and destroy during our application's lifetime.
For demo purposes, we will simulate a server call that returns other data. For this, create a file called other-users.json
inside the server
directory and paste this code into it:
[other-users.json] [ { "id": 5, "name": "Michael jackson", "email": "[email protected]", "birthday": "22/3/1974", "gender": "male", "status": "onhold", "role": "manager", "phoneNumbers": [ "+972-123-9873" ] }, (...) ]
On the accordion component template, we will add a button that will fetch this new data and implement the fetchData
method on the Component
class:
[accordion.ts] import { Component, Inject } from '@angular/core'; import...