IEnumerable "<"invention">" invention = from i in DataContext.invention where i.Sharable == true select i
Tuesday, 13 August 2024
new @let block in Angular templates
Thursday, 24 November 2022
angular v15 directive ngFor handling empty list
// hello.component.ts
// ng-of-empty.ts
Sunday, 20 November 2022
Angular functional guard to check on the user role to guard your routes
functional guard to check on the user role to guard your routes.
The functional guard accepts a param for the user role
Less verbose than a class based guard
use canMatch to skip a route dynamically in combination with functional guards.
👍 Super handy when a path should lead to different comp depending on some logic
👋 canLoad is going to be deprecated in favor of canMatch
Saturday, 19 November 2022
Directive composition API in Angular 15
our directive stand alone by adding standalone property inside directive declaration
import { Directive } from '@angular/core';
@Directive({
selector: '[appRedColor]',
host:{'style': 'color:red;'},
standalone: true
})
export class RedColorDirective {
constructor() { }
}
Now the text inside testdirective component will be displayed in red color.
<app-testdirective></app-testdirective>
And our code looks simple without adding an extra directive in component tag.
We can add more than one directive inside hostDirectives property.
@Component({
selector: 'app-testdirective',
templateUrl: './testdirective.component.html',
styleUrls: ['./testdirective.component.scss'],
hostDirectives:[RedColorDirective,HeightDirective,FontStyleDirective,......]
})
export class TestdirectiveComponent {
}
We can add hostDirectives inside an another directive as well.
Saturday, 15 October 2022
Reusable ng-template with parameters
Saturday, 18 June 2022
ng-container with ngTemplateOutlet and ng-template with context variable
Tuesday, 31 May 2022
use memo in your angular component template function call
Wednesday, 24 November 2021
Automatically Unsubscribe in Angular Component
Friday, 18 June 2021
What are the different types of binding available in Angular ?
<img [src]="ImageUrl">
<button (click)="onUpdate($event)">Save</button>
<input [(ngModel)]="name">
<button [attr.aria-label]="help">help</button>
<span [class.specialClass]="isSpecialClass">Special class</span>
<button [style.color]="isSpecialClass ? 'blue' : 'black'">Click Me</button>
What is Angular DSL?
A domain-specific language (DSL) is a computer language specialized to a particular application domain. Angular has its own Domain Specific Language (DSL) which allows us to write Angular specific html-like syntax on top of normal html. It has its own compiler that compiles this syntax to html that the browser can understand. This DSL is defined in NgModules such as animations, forms, and routing and navigation.
Basically you will see 3 main syntax in Angular DSL.
(): Used for Output and DOM events.
[]: Used for Input and specific DOM element attributes.
*: Structural directives(*ngFor or *ngIf) will affect/change the DOM structure.
Tuesday, 26 November 2019
Angular Template Syntax and NgClass & NgStyle Directives
| <!-- Native Class and Style Attributes --> | |
| <input class="is-danger my-button" style="border: none; color: blue"> | |
| <!-- Angular class and style Bindings --> | |
| <input [class.is-danger]="booleanProp" [style.border]="borderProp"> | |
| <!-- ngClass --> | |
| <input [ngClass]="{'is-danger': booleanProp, 'myButton': true}"> | |
| <input [ngClass]="isDangerButton"> | |
| <!-- ngStyle --> | |
| <input [ngStyle]="{'border': borderProp, 'color': colorProp}"> | |
| <input [ngStyle]="hasColorBorder"> | |
| <!-- | |
| booleanProp, borderProp, etc... | |
| would be properties from our | |
| Typescript class | |
-->
NgClass
NgClass can receive input via inline declarations, or a property/method from our TypeScript class. This can make the syntax feel more convoluted than it really is. Ultimately, NgClass can take the following as input:
All of the above examples are inline and could be replaced with a Typescript property/method as long as the expression returns valid input:
export class MyComponentClass {
myStringProperty = "is-info is-item has-border"; myArrayProperty = ['is-info', 'is-item', 'has-border']; myObjectProperty = {'is-info': true, 'is-item': true}; }
Key Points
NgStyle
NgClass and NgStyle share a significant amount of functionality and behavior. The key difference is:
Syntax
NgStyle takes a key-value pair object, where the key is a CSS style. An optional suffix can be added to the key, making keys such as this viable:
[ngStyle]="{font-size.px: 16}" Instead of [ngStyle]="{font-size: 16px}"
Similar to NgClass, NgStyle can be passed input inline or use a Typescript property/method.
[ngStyle]="myObjectExpressionProperty"Key Takeaways
|

