├── src
├── assets
│ ├── .gitkeep
│ └── shipping.json
├── app
│ ├── cart
│ │ ├── cart.component.css
│ │ ├── cart.component.html
│ │ └── cart.component.ts
│ ├── top-bar
│ │ ├── top-bar.component.css
│ │ ├── top-bar.component.html
│ │ └── top-bar.component.ts
│ ├── shipping
│ │ ├── shipping.component.css
│ │ ├── shipping.component.html
│ │ └── shipping.component.ts
│ ├── product-list
│ │ ├── product-list.component.css
│ │ ├── product-list.component.ts
│ │ └── product-list.component.html
│ ├── product-alerts
│ │ ├── product-alerts.component.css
│ │ ├── product-alerts.component.html
│ │ └── product-alerts.component.ts
│ ├── product-details
│ │ ├── product-details.component.css
│ │ ├── product-details.component.html
│ │ └── product-details.component.ts
│ ├── app.component.css
│ ├── app.component.html
│ ├── app.component.ts
│ ├── app-routing.module.ts
│ ├── products.ts
│ ├── cart.service.ts
│ ├── app.component.spec.ts
│ └── app.module.ts
├── favicon.ico
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── main.ts
├── index.html
├── test.ts
├── polyfills.ts
└── styles.css
├── e2e
├── src
│ ├── app.po.ts
│ └── app.e2e-spec.ts
├── tsconfig.json
└── protractor.conf.js
├── .editorconfig
├── tsconfig.app.json
├── tsconfig.spec.json
├── tsconfig.json
├── .browserslistrc
├── .gitignore
├── README.md
├── package.json
├── karma.conf.js
├── tslint.json
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/cart/cart.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/top-bar/top-bar.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/shipping/shipping.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/product-list/product-list.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/product-alerts/product-alerts.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/product-details/product-details.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 | p {
2 | font-family: Lato;
3 | }
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ashleshk/My-Store/master/src/favicon.ico
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/app/product-alerts/product-alerts.component.html:
--------------------------------------------------------------------------------
1 | 700">
2 |
3 |
--------------------------------------------------------------------------------
/src/app/top-bar/top-bar.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | My Store
4 |
5 |
6 |
7 | shopping_cartCheckout
8 |
9 |
--------------------------------------------------------------------------------
/src/assets/shipping.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "type": "Overnight",
4 | "price": 25.99
5 | },
6 | {
7 | "type": "2-Day",
8 | "price": 9.99
9 | },
10 | {
11 | "type": "Postal",
12 | "price": 2.99
13 | }
14 | ]
15 |
16 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'My-Store';
10 | }
11 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | const routes: Routes = [];
5 |
6 | @NgModule({
7 | imports: [RouterModule.forRoot(routes)],
8 | exports: [RouterModule]
9 | })
10 | export class AppRoutingModule { }
11 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | async navigateTo(): Promise {
5 | return browser.get(browser.baseUrl);
6 | }
7 |
8 | async getTitleText(): Promise {
9 | return element(by.css('app-root .content span')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "../tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "../out-tsc/e2e",
6 | "module": "commonjs",
7 | "target": "es2018",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/app",
6 | "types": []
7 | },
8 | "files": [
9 | "src/main.ts",
10 | "src/polyfills.ts"
11 | ],
12 | "include": [
13 | "src/**/*.d.ts"
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/top-bar/top-bar.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-top-bar',
5 | templateUrl: './top-bar.component.html',
6 | styleUrls: ['./top-bar.component.css']
7 | })
8 | export class TopBarComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit(): void {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/app/product-details/product-details.component.html:
--------------------------------------------------------------------------------
1 | Product Details
2 |
3 |
4 |
{{ product.name }}
5 |
{{ product.price | currency }}
6 |
{{ product.description }}
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "extends": "./tsconfig.json",
4 | "compilerOptions": {
5 | "outDir": "./out-tsc/spec",
6 | "types": [
7 | "jasmine"
8 | ]
9 | },
10 | "files": [
11 | "src/test.ts",
12 | "src/polyfills.ts"
13 | ],
14 | "include": [
15 | "src/**/*.spec.ts",
16 | "src/**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/src/app/products.ts:
--------------------------------------------------------------------------------
1 | export const products = [
2 | {
3 | name: 'Phone XL',
4 | price: 799,
5 | description: 'A large phone with one of the best screens'
6 | },
7 | {
8 | name: 'Phone Mini',
9 | price: 699,
10 | description: 'A great phone with one of the best cameras'
11 | },
12 | {
13 | name: 'Phone Standard',
14 | price: 299,
15 | description: ''
16 | }
17 | ];
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MyStore
6 |
7 |
8 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/app/shipping/shipping.component.html:
--------------------------------------------------------------------------------
1 | Shipping Prices
2 |
3 |
4 |
5 | {{shipping.type}}
6 | {{shipping.price | currency}}
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/app/shipping/shipping.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import {CartService} from '../cart.service';
3 | @Component({
4 | selector: 'app-shipping',
5 | templateUrl: './shipping.component.html',
6 | styleUrls: ['./shipping.component.css']
7 | })
8 | export class ShippingComponent implements OnInit {
9 |
10 | shippingCosts;
11 | constructor( private cartService: CartService) { }
12 |
13 | ngOnInit(): void {
14 | this.shippingCosts =this.cartService.getShippingPrices();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */
2 | {
3 | "compileOnSave": false,
4 | "compilerOptions": {
5 | "baseUrl": "./",
6 | "outDir": "./dist/out-tsc",
7 | "sourceMap": true,
8 | "declaration": false,
9 | "downlevelIteration": true,
10 | "experimentalDecorators": true,
11 | "moduleResolution": "node",
12 | "importHelpers": true,
13 | "target": "es2015",
14 | "module": "es2020",
15 | "lib": [
16 | "es2018",
17 | "dom"
18 | ]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/app/cart.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 |
3 | import { HttpClient } from '@angular/common/http';
4 |
5 |
6 | @Injectable({
7 | providedIn: 'root'
8 | })
9 | export class CartService {
10 |
11 | items= [];
12 |
13 | constructor( private http: HttpClient) { }
14 |
15 | addToCart(product) {
16 | this.items.push(product);
17 | }
18 |
19 | getItems() {
20 | return this.items;
21 | }
22 |
23 | clearCart() {
24 | this.items = [];
25 | return this.items;
26 | }
27 |
28 | getShippingPrices(){
29 | return this.http.get('/assets/shipping.json');
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/app/cart/cart.component.html:
--------------------------------------------------------------------------------
1 | Cart
2 |
3 | Shipping Prices
4 |
5 |
6 | {{ item.name }}
7 | {{ item.price | currency }}
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/app/product-alerts/product-alerts.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Input } from '@angular/core';
3 | import { Output, EventEmitter } from '@angular/core';
4 |
5 | @Component({
6 | selector: 'app-product-alerts',
7 | templateUrl: './product-alerts.component.html',
8 | styleUrls: ['./product-alerts.component.css']
9 | })
10 | export class ProductAlertsComponent implements OnInit {
11 |
12 | @Input() product;
13 | //The @Input() decorator indicates that the property value passes in
14 | //from the component's parent, the product list component.
15 | @Output() notify = new EventEmitter();
16 |
17 | constructor() { }
18 |
19 | ngOnInit(): void {
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // This file can be replaced during build by using the `fileReplacements` array.
2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
3 | // The list of file replacements can be found in `angular.json`.
4 |
5 | export const environment = {
6 | production: false
7 | };
8 |
9 | /*
10 | * For easier debugging in development mode, you can import the following file
11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
12 | *
13 | * This import should be commented out in production mode because it will have a negative impact
14 | * on performance if an error is thrown.
15 | */
16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
17 |
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 | import { browser, logging } from 'protractor';
3 |
4 | describe('workspace-project App', () => {
5 | let page: AppPage;
6 |
7 | beforeEach(() => {
8 | page = new AppPage();
9 | });
10 |
11 | it('should display welcome message', async () => {
12 | await page.navigateTo();
13 | expect(await page.getTitleText()).toEqual('My-Store app is running!');
14 | });
15 |
16 | afterEach(async () => {
17 | // Assert that there are no errors emitted from the browser
18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19 | expect(logs).not.toContain(jasmine.objectContaining({
20 | level: logging.Level.SEVERE,
21 | } as logging.Entry));
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/.browserslistrc:
--------------------------------------------------------------------------------
1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 |
5 | # For the full list of supported browsers by the Angular framework, please see:
6 | # https://angular.io/guide/browser-support
7 |
8 | # You can see what browsers were selected by your queries by running:
9 | # npx browserslist
10 |
11 | last 1 Chrome version
12 | last 1 Firefox version
13 | last 2 Edge major versions
14 | last 2 Safari major versions
15 | last 2 iOS major versions
16 | Firefox ESR
17 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events*.json
15 | speed-measure-plugin*.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 |
44 | # System Files
45 | .DS_Store
46 | Thumbs.db
47 |
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/zone-testing';
4 | import { getTestBed } from '@angular/core/testing';
5 | import {
6 | BrowserDynamicTestingModule,
7 | platformBrowserDynamicTesting
8 | } from '@angular/platform-browser-dynamic/testing';
9 |
10 | declare const require: {
11 | context(path: string, deep?: boolean, filter?: RegExp): {
12 | keys(): string[];
13 | (id: string): T;
14 | };
15 | };
16 |
17 | // First, initialize the Angular testing environment.
18 | getTestBed().initTestEnvironment(
19 | BrowserDynamicTestingModule,
20 | platformBrowserDynamicTesting()
21 | );
22 | // Then we find all the tests.
23 | const context = require.context('./', true, /\.spec\.ts$/);
24 | // And load the modules.
25 | context.keys().map(context);
26 |
--------------------------------------------------------------------------------
/src/app/product-list/product-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { products } from '../products';
3 | @Component({
4 | selector: 'app-product-list',
5 | templateUrl: './product-list.component.html',
6 | styleUrls: ['./product-list.component.css']
7 | })
8 | export class ProductListComponent{
9 |
10 | products = products;
11 |
12 | share() {
13 | window.alert('The product has been shared!');
14 | }
15 |
16 | onNotify() {
17 | window.alert('You will be notified when the product goes on sale');
18 | }
19 |
20 | }
21 |
22 | /*
23 | Why onNotify() define here ? if raised by product-alerts;
24 | Recall that it's the parent, product list component—not
25 | the product alerts component—that acts when the child
26 | raises the event.
27 | */
28 |
29 | /**
30 | * service is an instance of a class that you can make
31 | * available to any part of your application using
32 | * Angular's dependency injection system.
33 | *
34 | */
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 | // Protractor configuration file, see link for more information
3 | // https://github.com/angular/protractor/blob/master/lib/config.ts
4 |
5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
6 |
7 | /**
8 | * @type { import("protractor").Config }
9 | */
10 | exports.config = {
11 | allScriptsTimeout: 11000,
12 | specs: [
13 | './src/**/*.e2e-spec.ts'
14 | ],
15 | capabilities: {
16 | browserName: 'chrome'
17 | },
18 | directConnect: true,
19 | SELENIUM_PROMISE_MANAGER: false,
20 | baseUrl: 'http://localhost:4200/',
21 | framework: 'jasmine',
22 | jasmineNodeOpts: {
23 | showColors: true,
24 | defaultTimeoutInterval: 30000,
25 | print: function() {}
26 | },
27 | onPrepare() {
28 | require('ts-node').register({
29 | project: require('path').join(__dirname, './tsconfig.json')
30 | });
31 | jasmine.getEnv().addReporter(new SpecReporter({
32 | spec: {
33 | displayStacktrace: StacktraceOption.PRETTY
34 | }
35 | }));
36 | }
37 | };
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MyStore
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 11.0.3.
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
28 |
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async () => {
7 | await TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | });
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'My-Store'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.componentInstance;
26 | expect(app.title).toEqual('My-Store');
27 | });
28 |
29 | it('should render title', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.nativeElement;
33 | expect(compiled.querySelector('.content span').textContent).toContain('My-Store app is running!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/src/app/cart/cart.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit} from '@angular/core';
2 | import { CartService } from '../cart.service';
3 | import { FormBuilder } from '@angular/forms';
4 |
5 | @Component({
6 | selector: 'app-cart',
7 | templateUrl: './cart.component.html',
8 | styleUrls: ['./cart.component.css']
9 | })
10 | export class CartComponent implements OnInit{
11 | items;
12 | checkoutForm;
13 | // To gather the user's name and address, set the
14 | //checkoutForm property with a form model containing name
15 | //and address fields, using the FormBuilder group() method.
16 | // Add this between the curly braces, {}, of the constructor.
17 | constructor(private cartService: CartService,
18 | private formBuilder: FormBuilder
19 | ) {
20 | this.checkoutForm =this.formBuilder.group({
21 | name:'',
22 | address:''
23 | });
24 | }
25 | ngOnInit() {
26 | this.items = this.cartService.getItems();
27 | }
28 |
29 | onSubmit(customerData){
30 | //PRocess checkout data here
31 | this.items = this.cartService.clearCart();
32 | this.checkoutForm.reset();
33 |
34 | console.warn('Your Order has been submitted', customerData);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/app/product-list/product-list.component.html:
--------------------------------------------------------------------------------
1 | Products
2 |
3 |
10 |
17 |
18 |
19 |
24 |
25 |
26 | Description: {{ product.description }}
27 |
28 |
29 |
32 |
33 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-store",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~11.0.3",
15 | "@angular/common": "~11.0.3",
16 | "@angular/compiler": "~11.0.3",
17 | "@angular/core": "~11.0.3",
18 | "@angular/forms": "~11.0.3",
19 | "@angular/platform-browser": "~11.0.3",
20 | "@angular/platform-browser-dynamic": "~11.0.3",
21 | "@angular/router": "~11.0.3",
22 | "rxjs": "~6.6.0",
23 | "tslib": "^2.0.0",
24 | "zone.js": "~0.10.2"
25 | },
26 | "devDependencies": {
27 | "@angular-devkit/build-angular": "~0.1100.3",
28 | "@angular/cli": "~11.0.3",
29 | "@angular/compiler-cli": "~11.0.3",
30 | "@types/jasmine": "~3.6.0",
31 | "@types/node": "^12.11.1",
32 | "codelyzer": "^6.0.0",
33 | "jasmine-core": "~3.6.0",
34 | "jasmine-spec-reporter": "~5.0.0",
35 | "karma": "~5.1.0",
36 | "karma-chrome-launcher": "~3.1.0",
37 | "karma-coverage": "~2.0.3",
38 | "karma-jasmine": "~4.0.0",
39 | "karma-jasmine-html-reporter": "^1.5.0",
40 | "protractor": "~7.0.0",
41 | "ts-node": "~8.3.0",
42 | "tslint": "~6.1.0",
43 | "typescript": "~4.0.2"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | jasmine: {
17 | // you can add configuration options for Jasmine here
18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19 | // for example, you can disable the random execution with `random: false`
20 | // or set a specific seed with `seed: 4321`
21 | },
22 | clearContext: false // leave Jasmine Spec Runner output visible in browser
23 | },
24 | jasmineHtmlReporter: {
25 | suppressAll: true // removes the duplicated traces
26 | },
27 | coverageReporter: {
28 | dir: require('path').join(__dirname, './coverage/My-Store'),
29 | subdir: '.',
30 | reporters: [
31 | { type: 'html' },
32 | { type: 'text-summary' }
33 | ]
34 | },
35 | reporters: ['progress', 'kjhtml'],
36 | port: 9876,
37 | colors: true,
38 | logLevel: config.LOG_INFO,
39 | autoWatch: true,
40 | browsers: ['Chrome'],
41 | singleRun: false,
42 | restartOnFileChange: true
43 | });
44 | };
45 |
--------------------------------------------------------------------------------
/src/app/product-details/product-details.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute } from '@angular/router';
3 |
4 | import { products } from '../products';
5 | import { CartService } from '../cart.service';
6 |
7 | @Component({
8 | selector: 'app-product-details',
9 | templateUrl: './product-details.component.html',
10 | styleUrls: ['./product-details.component.css']
11 | })
12 | export class ProductDetailsComponent implements OnInit {
13 |
14 | product;
15 | addToCart(product) {
16 | this.cartService.addToCart(product);
17 | window.alert('Your product has been added to the cart!');
18 | }
19 | constructor(
20 | private route: ActivatedRoute,
21 | /**
22 | * ActivatedRoute is specific to each component that the
23 | * Angular Router loads. ActivatedRoute contains
24 | * information about the route and the route's
25 | * parameters.
26 |
27 | By injecting ActivatedRoute, you are configuring the
28 | component to use a service. The Managing Data step
29 | covers services in more detail.
30 | */
31 |
32 | // Inject the cart service by adding it to the constructor().
33 | private cartService: CartService
34 | ) { }
35 |
36 | ngOnInit(): void {
37 | this.route.paramMap.subscribe(params => {
38 | this.product = products[+params.get('productId')];
39 | /**The route parameters correspond to the path
40 | * variables you define in the route. The URL
41 | * that matches the route provides the productId.
42 | * Angular uses the productId to display the
43 | * details for each unique product. */
44 |
45 | });
46 | }
47 |
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { HttpClientModule } from '@angular/common/http';
4 | import { AppRoutingModule } from './app-routing.module';
5 | import { AppComponent } from './app.component';
6 | import { ProductListComponent } from './product-list/product-list.component';
7 | import { TopBarComponent } from './top-bar/top-bar.component';
8 | import { ReactiveFormsModule } from '@angular/forms';
9 | import { RouterModule } from '@angular/router';
10 | import { ProductAlertsComponent } from './product-alerts/product-alerts.component';
11 | import { ProductDetailsComponent } from './product-details/product-details.component';
12 | import { CartComponent } from './cart/cart.component';
13 | import { ShippingComponent } from './shipping/shipping.component';
14 |
15 | @NgModule({
16 | declarations: [
17 | AppComponent,
18 | ProductListComponent,
19 | TopBarComponent,
20 | ProductAlertsComponent,
21 | ProductDetailsComponent,
22 | CartComponent,
23 | ShippingComponent
24 | ],
25 | imports: [
26 | BrowserModule,
27 | AppRoutingModule,
28 | HttpClientModule,
29 | ReactiveFormsModule,
30 | RouterModule.forRoot([
31 | { path: '', component: ProductListComponent },
32 | { path: 'products/:productId', component: ProductDetailsComponent },
33 | { path: 'cart', component: CartComponent },
34 | { path: 'shipping' , component: ShippingComponent}
35 | ])
36 | ],
37 | providers: [],
38 | bootstrap: [AppComponent]
39 | })
40 | export class AppModule { }
41 |
42 | // Servers often return data in the form of a stream.
43 | // Streams are useful because they make it easy to transform
44 | // the returned data and make modifications to the way you
45 | // request that data.
46 |
47 | // Angular HttpClient is a built-in way to fetch data from
48 | // external APIs and provide them to your application as a
49 | // stream.
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE11 requires the following for NgClass support on SVG elements */
22 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
23 |
24 | /**
25 | * Web Animations `@angular/platform-browser/animations`
26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
28 | */
29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
30 |
31 | /**
32 | * By default, zone.js will patch all possible macroTask and DomEvents
33 | * user can disable parts of macroTask/DomEvents patch by setting following flags
34 | * because those flags need to be set before `zone.js` being loaded, and webpack
35 | * will put import in the top of bundle, so user need to create a separate file
36 | * in this directory (for example: zone-flags.ts), and put the following flags
37 | * into that file, and then add the following code before importing zone.js.
38 | * import './zone-flags';
39 | *
40 | * The flags allowed in zone-flags.ts are listed here.
41 | *
42 | * The following flags will work for all browsers.
43 | *
44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
47 | *
48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
50 | *
51 | * (window as any).__Zone_enable_cross_context_check = true;
52 | *
53 | */
54 |
55 | /***************************************************************************************************
56 | * Zone JS is required by default for Angular itself.
57 | */
58 | import 'zone.js/dist/zone'; // Included with Angular CLI.
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 | /* Global Styles */
3 |
4 | * {
5 | font-family: 'Roboto', Arial, sans-serif;
6 | color: #616161;
7 | box-sizing: border-box;
8 | -webkit-font-smoothing: antialiased;
9 | -moz-osx-font-smoothing: grayscale;
10 | }
11 |
12 | body {
13 | margin: 0;
14 | }
15 |
16 | .container {
17 | display: flex;
18 | flex-direction: row;
19 | }
20 |
21 | router-outlet + * {
22 | padding: 0 16px;
23 | }
24 |
25 | /* Text */
26 |
27 | h1 {
28 | font-size: 32px;
29 | }
30 |
31 | h2 {
32 | font-size: 20px;
33 | }
34 |
35 | h1, h2 {
36 | font-weight: lighter;
37 | }
38 |
39 | p {
40 | font-size: 14px;
41 | }
42 |
43 | /* Hyperlink */
44 |
45 | a {
46 | cursor: pointer;
47 | color: #1976d2;
48 | text-decoration: none;
49 | }
50 |
51 | a:hover {
52 | opacity: 0.8;
53 | }
54 |
55 | /* Input */
56 |
57 | input {
58 | font-size: 14px;
59 | border-radius: 2px;
60 | padding: 8px;
61 | margin-bottom: 16px;
62 | border: 1px solid #BDBDBD;
63 | }
64 |
65 | label {
66 | font-size: 12px;
67 | font-weight: bold;
68 | margin-bottom: 4px;
69 | display: block;
70 | text-transform: uppercase;
71 | }
72 |
73 | /* Button */
74 | .button, button {
75 | display: inline-flex;
76 | align-items: center;
77 | padding: 8px 16px;
78 | border-radius: 2px;
79 | font-size: 14px;
80 | cursor: pointer;
81 | background-color: #1976d2;
82 | color: white;
83 | border: none;
84 | }
85 |
86 | .button:hover, button:hover {
87 | opacity: 0.8;
88 | font-weight: normal;
89 | }
90 |
91 | .button:disabled, button:disabled {
92 | opacity: 0.5;
93 | cursor: auto;
94 | }
95 |
96 | /* Fancy Button */
97 |
98 | .fancy-button {
99 | background-color: white;
100 | color: #1976d2;
101 | }
102 |
103 | .fancy-button i.material-icons {
104 | color: #1976d2;
105 | padding-right: 4px;
106 | }
107 |
108 | /* Top Bar */
109 |
110 | app-top-bar {
111 | width: 100%;
112 | height: 68px;
113 | background-color: #1976d2;
114 | padding: 16px;
115 | display: flex;
116 | flex-direction: row;
117 | justify-content: space-between;
118 | align-items: center;
119 | }
120 |
121 | app-top-bar h1 {
122 | color: white;
123 | margin: 0;
124 | }
125 |
126 | /* Checkout Cart, Shipping Prices */
127 |
128 | .cart-item, .shipping-item {
129 | width: 100%;
130 | min-width: 400px;
131 | max-width: 450px;
132 | display: flex;
133 | flex-direction: row;
134 | justify-content: space-between;
135 | padding: 16px 32px;
136 | margin-bottom: 8px;
137 | border-radius: 2px;
138 | background-color: #EEEEEE;
139 | }
140 |
141 |
142 | /*
143 | Copyright Google LLC. All Rights Reserved.
144 | Use of this source code is governed by an MIT-style license that
145 | can be found in the LICENSE file at https://angular.io/license
146 | */
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tslint:recommended",
3 | "rulesDirectory": [
4 | "codelyzer"
5 | ],
6 | "rules": {
7 | "align": {
8 | "options": [
9 | "parameters",
10 | "statements"
11 | ]
12 | },
13 | "array-type": false,
14 | "arrow-return-shorthand": true,
15 | "curly": true,
16 | "deprecation": {
17 | "severity": "warning"
18 | },
19 | "eofline": true,
20 | "import-blacklist": [
21 | true,
22 | "rxjs/Rx"
23 | ],
24 | "import-spacing": true,
25 | "indent": {
26 | "options": [
27 | "spaces"
28 | ]
29 | },
30 | "max-classes-per-file": false,
31 | "max-line-length": [
32 | true,
33 | 140
34 | ],
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-console": [
47 | true,
48 | "debug",
49 | "info",
50 | "time",
51 | "timeEnd",
52 | "trace"
53 | ],
54 | "no-empty": false,
55 | "no-inferrable-types": [
56 | true,
57 | "ignore-params"
58 | ],
59 | "no-non-null-assertion": true,
60 | "no-redundant-jsdoc": true,
61 | "no-switch-case-fall-through": true,
62 | "no-var-requires": false,
63 | "object-literal-key-quotes": [
64 | true,
65 | "as-needed"
66 | ],
67 | "quotemark": [
68 | true,
69 | "single"
70 | ],
71 | "semicolon": {
72 | "options": [
73 | "always"
74 | ]
75 | },
76 | "space-before-function-paren": {
77 | "options": {
78 | "anonymous": "never",
79 | "asyncArrow": "always",
80 | "constructor": "never",
81 | "method": "never",
82 | "named": "never"
83 | }
84 | },
85 | "typedef": [
86 | true,
87 | "call-signature"
88 | ],
89 | "typedef-whitespace": {
90 | "options": [
91 | {
92 | "call-signature": "nospace",
93 | "index-signature": "nospace",
94 | "parameter": "nospace",
95 | "property-declaration": "nospace",
96 | "variable-declaration": "nospace"
97 | },
98 | {
99 | "call-signature": "onespace",
100 | "index-signature": "onespace",
101 | "parameter": "onespace",
102 | "property-declaration": "onespace",
103 | "variable-declaration": "onespace"
104 | }
105 | ]
106 | },
107 | "variable-name": {
108 | "options": [
109 | "ban-keywords",
110 | "check-format",
111 | "allow-pascal-case"
112 | ]
113 | },
114 | "whitespace": {
115 | "options": [
116 | "check-branch",
117 | "check-decl",
118 | "check-operator",
119 | "check-separator",
120 | "check-type",
121 | "check-typecast"
122 | ]
123 | },
124 | "component-class-suffix": true,
125 | "contextual-lifecycle": true,
126 | "directive-class-suffix": true,
127 | "no-conflicting-lifecycle": true,
128 | "no-host-metadata-property": true,
129 | "no-input-rename": true,
130 | "no-inputs-metadata-property": true,
131 | "no-output-native": true,
132 | "no-output-on-prefix": true,
133 | "no-output-rename": true,
134 | "no-outputs-metadata-property": true,
135 | "template-banana-in-box": true,
136 | "template-no-negated-async": true,
137 | "use-lifecycle-interface": true,
138 | "use-pipe-transform-interface": true,
139 | "directive-selector": [
140 | true,
141 | "attribute",
142 | "app",
143 | "camelCase"
144 | ],
145 | "component-selector": [
146 | true,
147 | "element",
148 | "app",
149 | "kebab-case"
150 | ]
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "My-Store": {
7 | "projectType": "application",
8 | "schematics": {},
9 | "root": "",
10 | "sourceRoot": "src",
11 | "prefix": "app",
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/My-Store",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": "src/polyfills.ts",
20 | "tsConfig": "tsconfig.app.json",
21 | "aot": true,
22 | "assets": [
23 | "src/favicon.ico",
24 | "src/assets"
25 | ],
26 | "styles": [
27 | "src/styles.css"
28 | ],
29 | "scripts": []
30 | },
31 | "configurations": {
32 | "production": {
33 | "fileReplacements": [
34 | {
35 | "replace": "src/environments/environment.ts",
36 | "with": "src/environments/environment.prod.ts"
37 | }
38 | ],
39 | "optimization": true,
40 | "outputHashing": "all",
41 | "sourceMap": false,
42 | "namedChunks": false,
43 | "extractLicenses": true,
44 | "vendorChunk": false,
45 | "buildOptimizer": true,
46 | "budgets": [
47 | {
48 | "type": "initial",
49 | "maximumWarning": "2mb",
50 | "maximumError": "5mb"
51 | },
52 | {
53 | "type": "anyComponentStyle",
54 | "maximumWarning": "6kb",
55 | "maximumError": "10kb"
56 | }
57 | ]
58 | }
59 | }
60 | },
61 | "serve": {
62 | "builder": "@angular-devkit/build-angular:dev-server",
63 | "options": {
64 | "browserTarget": "My-Store:build"
65 | },
66 | "configurations": {
67 | "production": {
68 | "browserTarget": "My-Store:build:production"
69 | }
70 | }
71 | },
72 | "extract-i18n": {
73 | "builder": "@angular-devkit/build-angular:extract-i18n",
74 | "options": {
75 | "browserTarget": "My-Store:build"
76 | }
77 | },
78 | "test": {
79 | "builder": "@angular-devkit/build-angular:karma",
80 | "options": {
81 | "main": "src/test.ts",
82 | "polyfills": "src/polyfills.ts",
83 | "tsConfig": "tsconfig.spec.json",
84 | "karmaConfig": "karma.conf.js",
85 | "assets": [
86 | "src/favicon.ico",
87 | "src/assets"
88 | ],
89 | "styles": [
90 | "src/styles.css"
91 | ],
92 | "scripts": []
93 | }
94 | },
95 | "lint": {
96 | "builder": "@angular-devkit/build-angular:tslint",
97 | "options": {
98 | "tsConfig": [
99 | "tsconfig.app.json",
100 | "tsconfig.spec.json",
101 | "e2e/tsconfig.json"
102 | ],
103 | "exclude": [
104 | "**/node_modules/**"
105 | ]
106 | }
107 | },
108 | "e2e": {
109 | "builder": "@angular-devkit/build-angular:protractor",
110 | "options": {
111 | "protractorConfig": "e2e/protractor.conf.js",
112 | "devServerTarget": "My-Store:serve"
113 | },
114 | "configurations": {
115 | "production": {
116 | "devServerTarget": "My-Store:serve:production"
117 | }
118 | }
119 | }
120 | }
121 | }
122 | },
123 | "defaultProject": "My-Store"
124 | }
125 |
--------------------------------------------------------------------------------