-
Demystifying the syntax of structural directive
Structural directive is a special directive. Angular comes with a couple of them such as
ngIf
,ngFor
. Angular provides detailed documentation about the structural directive. There are two syntaxes to use a directive, the sugar syntax ( starting with an asterisk*
) and the<ng-template>
syntax. The sugar syntax is shorter because it combines the following two features of<ng-template>
binding. -
Hello Jekyll!
I haven’t written any blog for 3 years, because the blogger platform does not provide
markdown
support. Now that I have migrated it to Jekyll, and let’s blog! -
Array(n) constructor
JavaScript Array constructor can be used in the follow syntax.
const items1 = new Array(2); //(2) [empty × 2] //or const items2 = Array(2); //(2) [empty × 2]
-
Demystify typescript keyword type and typeof
In typescript, keyword 'type' is used to alias existing types or anonymous types. This is typescript feature, and it has nothing to do with JavaScript. While const/let are used to declare variable in JavaScript.
-
When the change detector of OnPush component of Angular runs?
There are lots posts about how change detector works in Angualr. But I can't find a simple answer about when the change detector runs in OnPush components. I assume you understand how change detection works. If not , here is what you need to know. Angular use both zone.js and change detection. Zone.js modify DOM api(such as event, setTimeout etc), if an api trigger an exection of angular function, angular change detection cycle kick off. However, change detection cycle and change detector are two different concept. Change detector detects change. Change detection cycle does not necessary make change detector detect change. An angular application is a component tree. Each component will has its own change detector. The change detection start from the root components' change detector, all the way to the bottom component's change detector, asking them to detect change inside their components. By default, all change detectors will detect accordingly, unless the a change detector is manually detached by developer or it belongs to an OnPush component.