What is .subscribe in Angular?

I’m going through angular-tour-of-heroes app, and I encountered .subscribe method in routing. Can someone explain what’s going on here? Link for the app: https://embed.plnkr.co/?show=preview Inside hero-detail.component.ts file,

Angular: Get current index in ngFor

As per OP’s comment on question : So, I am trying to get the index of the ngFor in order to do a comparison to array of data before triggering another function. For example, the test() function will be triggered when I click a button, then it will check the current index, and do something …

Read more

What is pipe for in RxJS?

The “pipeable” (former “lettable”) operators is the current and recommended way of using operators since RxJS 5.5. I strongly recommend you to read the official documentation on pipeable operators The main difference is that it’s easier to make custom operators and that it’s better treeshakable while not altering some global Observable object that could possible make collisions if two different …

Read more

How to upgrade Angular CLI to the latest version

After reading some issues reported on the GitHub repository, I found the solution. In order to update the angular-cli package installed globally in your system, you need to run: Depending on your system, you may need to prefix the above commands with sudo. Also, most likely you want to also update your local project version, because …

Read more

ngFor with index as value in attribute

I would use this syntax to set the index value into an attribute of the HTML element: Angular >= 2 You have to use let to declare the value rather than #. Angular = 1 Here is the updated plunkr: http://plnkr.co/edit/LiCeyKGUapS5JKkRWnUJ?p=preview.

How to use *ngIf else?

Angular 4 and 5: using else : you can also use then else : or then alone : Demo : Plunker Details: <ng-template>: is Angular’s own implementation of the <template> tag which is according to MDN : The HTML <template> element is a mechanism for holding client-side content that is not to be rendered when …

Read more

Can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’

RC6/RC7/Final release FIX To fix this error, you just need to import ReactiveFormsModule from @angular/forms in your module. Here’s the example of a basic module with ReactiveFormsModule import: To explain further, formGroup is a selector for directive named FormGroupDirective that is a part of ReactiveFormsModule, hence the need to import it. It is used to …

Read more