Skip to content

Instantly share code, notes, and snippets.

@jhades
jhades / action-method.ts
Last active December 26, 2021 08:03
How to build Angular 2 apps using Observable Data Services - Pitfalls to avoid
addTodo(newTodo:Todo):Observable {
let obs = this.todoBackendService.saveTodo(newTodo);
obs.subscribe(
res => {
this._todos.next(this._todos.getValue().push(newTodo));
});
return obs;
}
@jhades
jhades / 01.ts
Last active October 28, 2021 05:12
Angular Dependency Injection: Complete Guide - https://blog.angular-university.io/angular-dependency-injection
export class CoursesService() {
http: HttpClient;
constructor() {
this.http = new HttpClient(... dependencies needed by HTTPClient ...);
}
...
}
@jhades
jhades / 01.ts
Last active October 25, 2021 19:42
RxJs mapping operators
const http$ : Observable<Course[]> = this.http.get('/api/courses');
http$
.pipe(
tap(() => console.log('HTTP request executed')),
map(res => Object.values(res['payload']))
)
.subscribe(
courses => console.log("courses", courses)
@jhades
jhades / 01.ts
Last active September 16, 2021 06:10
Content Projection
@Component({
selector: 'app-root',
template: `
<h1>FA Input</h1>
<fa-input icon="envelope" (value)="onNewValue($event)"></fa-input>
<fa-input icon="lock" (value)="onNewValue($event)"></fa-input>
@jhades
jhades / 01.ts
Last active August 3, 2021 05:07
Functional Reactive Programming for Angular Developers - RxJs and Observables
const obs = interval(1000).pipe(take(5));
@jhades
jhades / 01.ts
Last active July 28, 2021 07:28
Angular Router Introduction: Child Routes, Auxiliary Routes, Master Detail - http://blog.angular-university.io/angular2-router
export const routeConfig:Routes = [
{
path: 'home',
component: Home
},
{
path: 'lessons',
component: AllLessons
}
];
@jhades
jhades / 01.json
Last active June 13, 2021 21:51
Angular Universal Guide
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist-server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
}
}
onSelectUser(participantId:string) {
this.participantsService.findParticipantById(parseInt(participantId))
.pipe(
debug(LogginLevel.DEBUG, "Loading participant from backend")
)
.subscribe(
participant => {
...
},
<div class="container" *ngIf="userLoggedIn">
.... visible only to authenticated users
<button *ngIf="user.admin">Delete User</button>
</div>
@Component({
selector:'app',
template: `
<button (click)="save()">Save Lesson</button>
<lessons-list [lessons]="lessons"></lessons-list>
`
})
export class App {
constructor(private lessonsService: LessonsService) {