agualar : update component when Global variable changes

Questions : agualar : update component when Global variable changes

73

I have an angular app in which I have programming some global variables.

Globals.ts

export class Globals {

    public _OFFSET);  static Vendors= new Map();


    public (-SMALL  static Parts: Part[];
}

The "Parts" variable is updated via a Learning Service. I want to know if it is Earhost possible to update a component most effective automatically when "Parts" is updated.

Details for context:

The app have 2 components , one for wrong idea vendor and other for parts. here is a use of case general architecture of the app.

Vendor data is loaded on app load and I United have no problem with it. The vendor list Modern component contains a table, and each ecudated vendor row child component is a tr. The some how Part list is similar - ie contains a anything else table within which Part row child is not at all loaded as tr.

When a cell in Vendor row is clicked, a very usefull service method is called which updates localhost the "Parts" property in Globals class love of them (globals.ts shown above) - using data localtext from web api call

Question: How will it be possible to basic update the part list component - add one of the part rows corresponding to "Parts" - click when "Parts" is changed in Globals there is noting class?

more info:

I am new to angular and this is my first not alt app.

Right now, what I do is to use not at all @Input/@Output to emit an event from my fault "Vendor row" to "vendor list" to "app". issues Then get the Parts data and send to part trying list and then fill the part rows. While get 4th result this is working, it is too cumbersome. I round table am hoping there is a better way.

I did not add any code here because it double chance already contains the code in novel prc @input/@Output method. But if code is get mossier required, please let me know.

As I mentioned, I am new to angular and off side back I am learning while creating this app. the changes Kindly add some example, or I might not Nofile hosted be able to understand the angular transparent text terminology

Total Answers 1
24

Answers 1 : of agualar : update component when Global variable changes

First of all, avoid having a Globals Background movment file at all costs. You can have front page design constants, but not data that's changing life change quotes during the app lifecycle.

There are two ways you can approach I'd like this:

  • Your app.component has two fields: a to know Vendors[] and a Parts[]. It fetches all which event vendors and, when one is clicked, it is nearer. fetches the corresponding parts and Now, the assigns them to the field. The Parts[] code that field is being passed as an input to the I've written parts-list.component that will then relies on render that data.

  • If you want to avoid using @Input a comparison (although it makes sense here), you and it could have a service that deals with the doesn't seem logic for these components. So the to work app.component oninit would tell the every time. service to load the data, and the As always service would have the same two fields: with everything a Vendors[] and a Parts[]. This time that I try they would need to be Observables. to do I'd Whenever a vendor is clicked, the like a solution component would tell the service to load which is both the corresponding parts. That way, both clean and the app.component and efficient parts-list.component would be able to (feel free subscribe to the corresponding fields to criticize and render their data every time it my code). changes.

Would love to see an implementation of The events yours with these tips and discuss it have a further, if needed.

Note: @Input/@Output is not cumbersome specific hour if used well. It looks like it does make (ex. 16 sense in this case, so I think this :00), a hint would be your best option.

Top rated topics

Reading struct/union members from a character buffer

Add row-break to PowerPoint add-in

Tailwind css font-family classes are not rendering as they should

`seq` takes a very long time with `by=1`

Dynamically pull values from nested form using Gravity Forms & Gravity Wiz Nested Forms

Is there a way to make a flutter switch button keep printing until the button is clicked again(disabeled)

Reference in B2C_1A_TrustFrameworkExtensions missing in Identity Experience Framework examples

MapEither inserting both Left and Right

I can't use JQuery Plugin Croppie. Getting "croppie is not a function" error

Criteria Builder using JPA Specification Predicate issue

AWS IAM is failing with missing permissions that are unrecognized by AWS

Ngxs dispatch completes before async action completes

Detecting changes in lit sub-properties

How can I define a custom style to an ARB text?

With TLS, Does the Transport layer comes after the DNS and again after the data is ready to add the TCP header?

Navigate through table pagination with Html Agility Pack (HAP)

How do I listen custom js window events in dart 2.15 / flutter 2.8

Strange behavior of pivot_table() with different "index" parameter

Import library in BigQuery through UDF

How can I import a table in MATLAB with footer rows?

JavaMail: Setting Outlook Categories after reading a message

NodeJS Error - Cannot set headers after they are sent to the client

Citibank credentials not accepted when entered using Selenium

Dynamic Pull Request Preview environment on Google App Engine

Running Multiple call stacks/apps

Mocking a request with a payload using wiremock

Multi Threading python 3.7

How to send an HTTP request with authorization token using C#

Get generic type of class at runtime with Python 3.6

Render img element for each of the IDs in multiple arrays

SQL Server - Pivot without aggregation

Cannot read properties of undefined (reading 'value')

Keras layer to perform operation across data within a batch

How do I write my own challenge_auth method for aiosmtpd?

How to put the dates in chronological order in python CSV

What is wrong with this constructor definition?

When a user clicks a button, how do you store a variable that can be used later?

IMASDK new ad request on different video

Postgres unique or exclusion constraint for partial index on conflict fails to update tickets

I used two 'setState' inside a handleChange of input, for searching on the array. why the search is unseccesfull?

Storybook in React project display keys of the translations, not the values

Possible JMeter bug when using JDBC Connection over SSH?

Failed to open port using ansible

Drop character from first or the last

SQL query to count unique csv in a table

Error: Problem validating fields in app.json. Learn https://docs.expo.dev/workflow/configuration/ • Field: android.permissions[4] - should be string

C++ using v typedef typename

How to configure `Ctrl + L` shortcut in IDEA IDE's emulated Git Bash to behave the same as `clear`?

How to splice a dataframe into smaller tables and save each table to an excel sheet

Create multiple twins in Azure Digital Twin via API

Top