Skip to content

Fetching data leo #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
!.vscode/extensions.json

# misc
/.angular/cache
/.sass-cache
/connect.lock
/coverage
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,23 +3,14 @@

This repository contains the code of the [Angular Core Deep Dive](https://angular-university.io/course/angular-course).

This course repository is updated to Angular v6, and there is a package-lock.json file available, for avoiding semantic versioning installation issues.
This course repository is updated to Angular v16:

![Angular Core Deep Dive](https://s3-us-west-1.amazonaws.com/angular-university/course-images/angular-core-in-depth-small.png)


# Installation pre-requisites

IMPORTANT: Please use the latest Node and especially NPM, to make sure the package-lock.json is used.

For running this project we need and npm installed on our machine. These are some tutorials to install node in different operating systems:

*Its important to install the latest version of Node*

- [Install Node and NPM on Windows](https://www.youtube.com/watch?v=8ODS6RM6x7g)
- [Install Node and NPM on Linux](https://www.youtube.com/watch?v=yUdHk-Dk_BY)
- [Install Node and NPM on Mac](https://www.youtube.com/watch?v=Imj8PgG3bZU)

IMPORTANT: Please use Node 18 (Long Term Support version). Note that Node 18 is not yet officially supported by the Angular CLI.

# Installing the Angular CLI

52 changes: 25 additions & 27 deletions angular.json
Original file line number Diff line number Diff line change
@@ -24,14 +24,32 @@
],
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"inject": true
},
"src/styles.css"
],
"scripts": []
"scripts": [
{
"input": "node_modules/document-register-element/build/document-register-element.js",
"inject": true
}
],
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
"budgets": [
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
@@ -41,9 +59,7 @@
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
@@ -76,7 +92,8 @@
"karmaConfig": "src/karma.conf.js",
"styles": [
{
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css"
"input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
"inject": true
},
"src/styles.css"
],
@@ -86,18 +103,6 @@
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
@@ -116,18 +121,11 @@
"devServerTarget": "angular-course:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "angular-course"
"cli": {
"analytics": "f1c06a76-7ca0-486f-aa03-e6051586f3c1"
}
}
30,755 changes: 22,881 additions & 7,874 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 33 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -8,46 +8,48 @@
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"server": "./node_modules/.bin/ts-node -O '{\"module\": \"commonjs\"}' ./server.ts"
"server": "ts-node -P ./server.tsconfig.json ./server.ts"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.2.0",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.6",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@angular/animations": "^16.0.0",
"@angular/cdk": "^16.0.0",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/elements": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/localize": "^16.0.0",
"@angular/material": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"body-parser": "^1.18.3",
"core-js": "^2.5.4",
"cors": "^2.8.5",
"document-register-element": "1.8.1",
"express": "^4.16.3",
"rxjs": "^6.0.0",
"zone.js": "~0.8.26"
"rxjs": "^6.5.4",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "~6.1.4",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.6",
"@angular-devkit/build-angular": "^16.0.0",
"@angular/cli": "^16.0.0",
"@angular/compiler-cli": "^16.0.0",
"@angular/language-service": "^16.0.0",
"@types/jasmine": "~3.6.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"@types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.7.0",
"protractor": "^7.0.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
"tslint": "~6.1.0",
"typescript": "~5.0.4"
}
}
3 changes: 2 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
@@ -4,12 +4,13 @@ import * as express from 'express';
import {Application} from "express";
import {getAllCourses} from './server/get-courses.route';
import {saveCourse} from './server/save-course.route';

const cors = require('cors');

const bodyParser = require('body-parser');

const app: Application = express();

app.use(cors({origin: true}));
app.use(bodyParser.json());

app.route('/api/courses').get(getAllCourses);
5 changes: 5 additions & 0 deletions server.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "commonjs"
}
}
5 changes: 3 additions & 2 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -7,10 +7,11 @@

<div>

<div class="courses">
<div class="courses" *ngIf="courses$ | async as courses">

<course-card *ngFor="let course of courses"
[course]="course">
(courseChanged)="save($event)"
[course]="course">

<course-image [src]="course.iconUrl"></course-image>

10 changes: 5 additions & 5 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { TestBed, async } from '@angular/core/testing';
import { TestBed, waitForAsync } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
it('should create the app', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'angular-course'`, async(() => {
it(`should have as title 'angular-course'`, waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('angular-course');
}));
it('should render title in a h1 tag', async(() => {
it('should render title in a h1 tag', waitForAsync(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
26 changes: 24 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { HttpClient } from '@angular/common/http';
import { HttpParams } from '@angular/common/http';
import {AfterViewInit, Component, ElementRef, OnInit, QueryList, ViewChild, ViewChildren} from '@angular/core';
import {COURSES} from '../db-data';
import {Course} from './model/course';
import {CourseCardComponent} from './course-card/course-card.component';
import {HighlightedDirective} from './directives/highlighted.directive';
import {Observable} from 'rxjs';
import { CoursesService } from './services/courses.service';

@Component({
selector: 'app-root',
@@ -12,16 +15,35 @@ import {Observable} from 'rxjs';
})
export class AppComponent implements OnInit {

courses$ : Observable<Course[]>;

courses = COURSES;
// courses;

constructor() {
constructor(private coursesService: CoursesService) {

}

ngOnInit() {

this.courses$ = this.coursesService.loadCourses();

}

save(course:Course) {

this.coursesService.saveCourse(course)
.subscribe(
() => console.log('Course Saved!')
)

}

// this.http.get('/api/courses', {params})
// .subscribe(
// courses => this.courses = courses
// );
// }



}
4 changes: 2 additions & 2 deletions src/app/course-card/course-card.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { CourseCardComponent } from './course-card.component';

describe('CourseCardComponent', () => {
let component: CourseCardComponent;
let fixture: ComponentFixture<CourseCardComponent>;

beforeEach(async(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ CourseCardComponent ]
})
5 changes: 4 additions & 1 deletion src/app/course-card/course-card.component.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import {
} from '@angular/core';
import {Course} from '../model/course';
import {CourseImageComponent} from '../course-image/course-image.component';
import { CoursesService } from '../services/courses.service';

@Component({
selector: 'course-card',
@@ -31,12 +32,14 @@ export class CourseCardComponent implements OnInit {
courseEmitter = new EventEmitter<Course>();


constructor() {
constructor(private coursesService: CoursesService) {

}

ngOnInit() {

console.log('coursesService course card', this.coursesService)

}


4 changes: 2 additions & 2 deletions src/app/course-image/course-image.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';

import { CourseImageComponent } from './course-image.component';

describe('CourseImageComponent', () => {
let component: CourseImageComponent;
let fixture: ComponentFixture<CourseImageComponent>;

beforeEach(async(() => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ CourseImageComponent ]
})
16 changes: 16 additions & 0 deletions src/app/services/courses.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { CoursesService } from './courses.service';

describe('CoursesService', () => {
let service: CoursesService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CoursesService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
30 changes: 30 additions & 0 deletions src/app/services/courses.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Course } from '../model/course';

@Injectable({
providedIn: 'root'
})
export class CoursesService {
courses$: Observable<Course[]>;

constructor(private http: HttpClient) { }

loadCourses(): Observable<Course[]> {
const params = new HttpParams()
.set("page", "1")
.set("pageSize", "10")

return this.courses$ = this.http.get<Course[]>('/api/courses', {params})
}

saveCourse(course:Course) {

const headers = new HttpHeaders()
.set("X-Auth", "userId")

return this.http.put(`/api/courses/${course.id}`, course, {headers})

}
}
9 changes: 0 additions & 9 deletions src/browserslist

This file was deleted.

2 changes: 1 addition & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -12,4 +12,4 @@ export const environment = {
* below file. Don't forget to comment it out in production mode
* because it will have a performance impact when errors are thrown
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
18 changes: 5 additions & 13 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
import '@angular/localize/init';
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
@@ -34,24 +38,12 @@
// import 'core-js/es6/weak-map';
// import 'core-js/es6/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following for the Reflect API. */
// import 'core-js/es6/reflect';


/** Evergreen browsers require these. **/
// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
import 'core-js/es7/reflect';


/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
**/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.

/**
* By default, zone.js will patch all possible macroTask and DomEvents
@@ -71,7 +63,7 @@ import 'core-js/es7/reflect';
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
import 'zone.js'; // Included with Angular CLI.



12 changes: 4 additions & 8 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone-testing';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
}
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
9 changes: 6 additions & 3 deletions src/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -4,8 +4,11 @@
"outDir": "../out-tsc/app",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
"files": [
"main.ts",
"polyfills.ts"
],
"include": [
"src/**/*.d.ts"
]
}
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -5,17 +5,17 @@
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"target": "ES2022",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
],
"useDefineForClassFields": false
}
}
9 changes: 4 additions & 5 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -72,7 +72,6 @@
"no-trailing-whitespace": true,
"no-unnecessary-initializer": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
@@ -117,12 +116,12 @@
"check-type"
],
"no-output-on-prefix": true,
"use-input-property-decorator": true,
"use-output-property-decorator": true,
"use-host-property-decorator": true,
"no-inputs-metadata-property": true,
"no-outputs-metadata-property": true,
"no-host-metadata-property": true,
"no-input-rename": true,
"no-output-rename": true,
"use-life-cycle-interface": true,
"use-lifecycle-interface": true,
"use-pipe-transform-interface": true,
"component-class-suffix": true,
"directive-class-suffix": true