What is the difference between component and directive?

Basically there are three types of directives in Angular2 according to documentation. Component Structural directives Attribute directives Component It is also a type of directive with template,styles and logic part which is most famous type of directive among all in Angular2. In this type of directive you can use other directives whether it is custom … Read more

How is Angular’s *ngFor loop implemented?

Here is a high level overview. Suppose you define your template like this: <span *ngFor=”let item of items”>{{item}}</span> Then it’s transformed to the following by the compiler: <ng-template let-item [ngForOf]=”items”> <span>{{item}}</span> </ng-template> Then Angular applies ngForOf directive to the template element. Since this directive’s host element is template, it injects the templateRef. It also injects … Read more

AngularJS Upgrade (1.5 to 1.6,1.7) Makes directive scope bindings undefined

The AngularJS team recommends that controller code that depends on scope bindings be moved into an $onInit function. function LayoutController($scope, LayoutDTO, LayoutPreviewDTO) { var self = this; this.$onInit = function () { // bindings will always be available here // regardless of the value of `preAssignBindingsEnabled`. self.layoutDTO = LayoutDTO; self.layoutPreviewDTO = LayoutPreviewDTO; var test = … Read more

How to extend / inherit components?

Alternative Solution: This answer of Thierry Templier is an alternative way to get around the problem. After some questions with Thierry Templier, I came to the following working example that meets my expectations as an alternative to inheritance limitation mentioned in this question: 1 – Create custom decorator: export function CustomComponent(annotation: any) { return function … Read more

Get Value From Select Option in Angular 4

As a general (see Stackblitz here: https://stackblitz.com/edit/angular-gh2rjx): HTML <select [(ngModel)]=”selectedOption”> <option *ngFor=”let o of options”> {{o.name}} </option> </select> <button (click)=”print()”>Click me</button> <p>Selected option: {{ selectedOption }}</p> <p>Button output: {{ printedOption }}</p> Typescript export class AppComponent { selectedOption: string; printedOption: string; options = [ { name: “option1”, value: 1 }, { name: “option2”, value: 2 } … Read more