REST API consumption – Angular Services and the Singleton Pattern-2
For the inclusion of a new set, we are using the POST method of the service that calls the API with the verb of the same name. We always pass the URL and, in this…
For the inclusion of a new set, we are using the POST method of the service that calls the API with the verb of the same name. We always pass the URL and, in this…
A characteristic that we must understand about Angular services is that, by default, every service instantiated by the dependency injection mechanism has the same reference; that is, a new object is not created, but reused.This…
In object-oriented software development, it is good practice to prioritize composition over inheritance, meaning that a class should be composed of other classes (preferably interfaces).In our previous example, we can see that the service class…
We studied how parent components, which can be either smart or presentational, can communicate with their child components by using attributes marked with the @Input decorator.However, when we need the opposite, the child component passes…
The information flow of a single-page application (SPA) can be quite complex and, if you don’t think about this flow from the beginning of your design, it can affect the productivity and quality of your…
After the *ngIf directive, the ngFor directive will probably be the directive that you will use the most in your Angular projects. Although simple, this directive can hide a performance and perception problem in the…
Now that we know the TypeScript inference mechanism, we can understand another feature present in it, type guards. Let’s consider these in the following example:function getDiscount(value: string | number) { if (typeof value === “number”) { return…
In TypeScript, by default, all function and method parameters are required and checked by the transpiler.If any parameter is optional, we can define it in the type it represents, as in the following example: function…
Building on our knowledge of basic types, let’s now create more complex data types. The first one we’re going to explore is classes. An essential element of object-oriented programming, the class represents a model, which…
JavaScript, despite not being a strongly typed language, has three types called primitives: For each of these primitive types, TypeScript already has a datatype that represents them, namely, Boolean, String, and Number, respectively. Important The…