More on Components Flashcards
There are two ways for setting/using an interface. What for and why?
One is just for data as data type.
export interface Product {…}
Second is like feature set (like implementing an interface in C# ) by defining methods and properties without any code, just structure
by Encapsulating styles in the component metadata
we won’t affect any other component in the application
What to do in order to implement custom pipe
Create a class with @Pipe decorator and implement PipeTransform interface.
Set logic in the transform method.
We need to add the custom pipe to the same angular module that would use this custom pipe. Add it to the declarations array.
Also, we need to import the pipe stuff.
Getter and setter
Often define a private variable (_name) and is used only by the getter or setter.
The benefit is that we can write custom code that will execute on getting/setting value
An arrow function is
compact syntax for defining a function.
Classic named function:
capitalizeName(product: IProduct) :string {
return product.ProductName.toUpperCase();
}
Arrow function:
(product: IProduct) => product.productName.toUpperCase();
Use arrow function any time you need to pass a function in to another function/method.