├── src
├── assets
│ └── .gitkeep
├── app
│ ├── app.component.css
│ ├── recipes
│ │ ├── recipes.component.css
│ │ ├── recipe-edit
│ │ │ ├── recipe-edit.component.css
│ │ │ ├── recipe-edit.component.html
│ │ │ └── recipe-edit.component.ts
│ │ ├── recipe-list
│ │ │ ├── recipe-list.component.css
│ │ │ ├── recipe-item
│ │ │ │ ├── recipe-item.component.css
│ │ │ │ ├── recipe-item.component.ts
│ │ │ │ └── recipe-item.component.html
│ │ │ ├── recipe-list.component.html
│ │ │ └── recipe-list.component.ts
│ │ ├── recipe-detail
│ │ │ ├── recipe-detail.component.css
│ │ │ ├── recipe-detail.component.ts
│ │ │ └── recipe-detail.component.html
│ │ ├── recipe-start
│ │ │ ├── recipe-start.component.css
│ │ │ ├── recipe-start.component.html
│ │ │ └── recipe-start.component.ts
│ │ ├── recipes.component.html
│ │ ├── recipe.model.ts
│ │ ├── recipes.component.ts
│ │ └── recipe.service.ts
│ ├── shopping-list
│ │ ├── shopping-list.component.css
│ │ ├── shopping-edit
│ │ │ ├── shopping-edit.component.css
│ │ │ ├── shopping-edit.component.ts
│ │ │ └── shopping-edit.component.html
│ │ ├── shopping-list.component.html
│ │ ├── shopping-list.component.ts
│ │ └── shopping-list.service.ts
│ ├── shared
│ │ ├── ingredient.model.ts
│ │ └── dropdown.directive.ts
│ ├── header
│ │ ├── header.component.ts
│ │ └── header.component.html
│ ├── app.component.html
│ ├── app.component.ts
│ ├── app.component.spec.ts
│ ├── app-routing.module.ts
│ └── app.module.ts
├── styles.css
├── environments
│ ├── environment.prod.ts
│ └── environment.ts
├── favicon.ico
├── tsconfig.app.json
├── index.html
├── tsconfig.spec.json
├── tslint.json
├── browserslist
├── main.ts
├── test.ts
├── karma.conf.js
└── polyfills.ts
├── e2e
├── src
│ ├── app.po.ts
│ └── app.e2e-spec.ts
├── tsconfig.e2e.json
└── protractor.conf.js
├── .editorconfig
├── tsconfig.json
├── .gitignore
├── README.md
├── package.json
├── tslint.json
└── angular.json
/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipes.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-edit/recipe-edit.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-list.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-list.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-detail/recipe-detail.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-start/recipe-start.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-edit/shopping-edit.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-item/recipe-item.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-start/recipe-start.component.html:
--------------------------------------------------------------------------------
1 |
Please select a Recipe!
2 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-edit/recipe-edit.component.html:
--------------------------------------------------------------------------------
1 |
2 | recipe-edit works!
3 |
4 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chandu-muthyala/recipe-book-Angular6/master/src/favicon.ico
--------------------------------------------------------------------------------
/src/app/shared/ingredient.model.ts:
--------------------------------------------------------------------------------
1 | export class Ingredient {
2 | constructor(public name: string, public amount: number) {}
3 | }
4 |
--------------------------------------------------------------------------------
/src/app/header/header.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-header',
5 | templateUrl: './header.component.html'
6 | })
7 | export class HeaderComponent {
8 | }
9 |
--------------------------------------------------------------------------------
/src/app/recipes/recipes.component.html:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "es2015",
6 | "types": []
7 | },
8 | "exclude": [
9 | "src/test.ts",
10 | "**/*.spec.ts"
11 | ]
12 | }
13 |
--------------------------------------------------------------------------------
/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://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 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/src/app/shared/dropdown.directive.ts:
--------------------------------------------------------------------------------
1 | import { Directive, HostListener, HostBinding } from '@angular/core';
2 |
3 | @Directive({
4 | selector: '[appDropdown]'
5 | })
6 | export class DropdownDirective {
7 | @HostBinding('class.open') isOpen = false;
8 |
9 | @HostListener('click') toggleOpen() {
10 | this.isOpen = !this.isOpen;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | MyFirstApp
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/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 | loadedFeature = 'recipe';
10 |
11 | onNavigate(feature: string) {
12 | this.loadedFeature = feature;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to angularJs!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "module": "commonjs",
6 | "types": [
7 | "jasmine",
8 | "node"
9 | ]
10 | },
11 | "files": [
12 | "test.ts",
13 | "polyfills.ts"
14 | ],
15 | "include": [
16 | "**/*.spec.ts",
17 | "**/*.d.ts"
18 | ]
19 | }
20 |
--------------------------------------------------------------------------------
/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-start/recipe-start.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-recipe-start',
5 | templateUrl: './recipe-start.component.html',
6 | styleUrls: ['./recipe-start.component.css']
7 | })
8 | export class RecipeStartComponent implements OnInit {
9 |
10 | constructor() { }
11 |
12 | ngOnInit() {
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed
5 | > 0.5%
6 | last 2 versions
7 | Firefox ESR
8 | not dead
9 | # IE 9-11
--------------------------------------------------------------------------------
/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.log(err));
13 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-list.component.html:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-list.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
15 |
16 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-item/recipe-item.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit, Input } from '@angular/core';
2 |
3 | import { Recipe } from '../../recipe.model';
4 |
5 | @Component({
6 | selector: 'app-recipe-item',
7 | templateUrl: './recipe-item.component.html',
8 | styleUrls: ['./recipe-item.component.css']
9 | })
10 | export class RecipeItemComponent implements OnInit {
11 | @Input() recipe: Recipe;
12 | @Input() index: number;
13 |
14 | ngOnInit() {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe.model.ts:
--------------------------------------------------------------------------------
1 | import { Ingredient } from '../shared/ingredient.model';
2 |
3 | export class Recipe {
4 | public name: string;
5 | public description: string;
6 | public imagePath: string;
7 | public ingredients: Ingredient[];
8 |
9 | constructor(name: string, desc: string, imagePath: string, ingredients: Ingredient[]) {
10 | this.name = name;
11 | this.description = desc;
12 | this.imagePath = imagePath;
13 | this.ingredients = ingredients;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "module": "es2015",
9 | "moduleResolution": "node",
10 | "emitDecoratorMetadata": true,
11 | "experimentalDecorators": true,
12 | "target": "es5",
13 | "typeRoots": [
14 | "node_modules/@types"
15 | ],
16 | "lib": [
17 | "es2017",
18 | "dom"
19 | ]
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-item/recipe-item.component.html:
--------------------------------------------------------------------------------
1 |
6 |
7 |
{{ recipe.name }}
8 |
{{ recipe.description }}
9 |
10 |
11 |
16 |
17 |
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 |
8 | # dependencies
9 | /node_modules
10 |
11 | # IDEs and editors
12 | /.idea
13 | .project
14 | .classpath
15 | .c9/
16 | *.launch
17 | .settings/
18 | *.sublime-workspace
19 |
20 | # IDE - VSCode
21 | .vscode/*
22 | !.vscode/settings.json
23 | !.vscode/tasks.json
24 | !.vscode/launch.json
25 | !.vscode/extensions.json
26 |
27 | # misc
28 | /.sass-cache
29 | /connect.lock
30 | /coverage
31 | /libpeerconnection.log
32 | npm-debug.log
33 | yarn-error.log
34 | testem.log
35 | /typings
36 |
37 | # System Files
38 | .DS_Store
39 | Thumbs.db
40 |
--------------------------------------------------------------------------------
/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 | * In development mode, to ignore zone related error stack frames such as
11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
12 | * import the following file, but please comment it out in production mode
13 | * because it will have performance impact when throw error
14 | */
15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI.
16 |
--------------------------------------------------------------------------------
/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: any;
11 |
12 | // First, initialize the Angular testing environment.
13 | getTestBed().initTestEnvironment(
14 | BrowserDynamicTestingModule,
15 | platformBrowserDynamicTesting()
16 | );
17 | // Then we find all the tests.
18 | const context = require.context('./', true, /\.spec\.ts$/);
19 | // And load the modules.
20 | context.keys().map(context);
21 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-edit/recipe-edit.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute, Params } from '@angular/router';
3 |
4 | @Component({
5 | selector: 'app-recipe-edit',
6 | templateUrl: './recipe-edit.component.html',
7 | styleUrls: ['./recipe-edit.component.css']
8 | })
9 | export class RecipeEditComponent implements OnInit {
10 | id: number;
11 | editMode = false;
12 |
13 | constructor(private route: ActivatedRoute) { }
14 |
15 | ngOnInit() {
16 | this.route.params
17 | .subscribe(
18 | (params: Params) => {
19 | this.id = +params['id'];
20 | this.editMode = params['id'] != null;
21 | }
22 | );
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/recipes/recipes.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { Recipe } from './recipe.model';
4 | import { RecipeService } from './recipe.service';
5 |
6 | @Component({
7 | selector: 'app-recipes',
8 | templateUrl: './recipes.component.html',
9 | styleUrls: ['./recipes.component.css'],
10 | providers: [RecipeService]
11 | })
12 | export class RecipesComponent implements OnInit {
13 | selectedRecipe: Recipe;
14 |
15 | constructor(private recipeService: RecipeService) { }
16 |
17 | ngOnInit() {
18 | this.recipeService.recipeSelected
19 | .subscribe(
20 | (recipe: Recipe) => {
21 | this.selectedRecipe = recipe;
22 | }
23 | );
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 |
3 | import { Ingredient } from '../shared/ingredient.model';
4 | import { ShoppingListService } from './shopping-list.service';
5 |
6 | @Component({
7 | selector: 'app-shopping-list',
8 | templateUrl: './shopping-list.component.html',
9 | styleUrls: ['./shopping-list.component.css']
10 | })
11 | export class ShoppingListComponent implements OnInit {
12 | ingredients: Ingredient[];
13 |
14 | constructor(private slService: ShoppingListService) { }
15 |
16 | ngOnInit() {
17 | this.ingredients = this.slService.getIngredients();
18 | this.slService.ingredientsChanged
19 | .subscribe(
20 | (ingredients: Ingredient[]) => {
21 | this.ingredients = ingredients;
22 | }
23 | );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-list/recipe-list.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { Router, ActivatedRoute } from '@angular/router';
3 |
4 | import { Recipe } from '../recipe.model';
5 | import { RecipeService } from '../recipe.service';
6 |
7 | @Component({
8 | selector: 'app-recipe-list',
9 | templateUrl: './recipe-list.component.html',
10 | styleUrls: ['./recipe-list.component.css']
11 | })
12 | export class RecipeListComponent implements OnInit {
13 | recipes: Recipe[];
14 |
15 | constructor(private recipeService: RecipeService,
16 | private router: Router,
17 | private route: ActivatedRoute) {
18 | }
19 |
20 | ngOnInit() {
21 | this.recipes = this.recipeService.getRecipes();
22 | }
23 |
24 | onNewRecipe() {
25 | this.router.navigate(['new'], {relativeTo: this.route});
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-list.service.ts:
--------------------------------------------------------------------------------
1 | import { Ingredient } from '../shared/ingredient.model';
2 | import { EventEmitter } from '@angular/core';
3 |
4 | export class ShoppingListService {
5 | ingredientsChanged = new EventEmitter();
6 | private ingredients: Ingredient[] = [
7 | new Ingredient('Apples', 5),
8 | new Ingredient('Tomatoes', 10),
9 | ];
10 |
11 | getIngredients() {
12 | return this.ingredients.slice();
13 | }
14 |
15 | addIngredient(ingredient: Ingredient) {
16 | this.ingredients.push(ingredient);
17 | this.ingredientsChanged.emit(this.ingredients.slice());
18 | }
19 |
20 | addIngredients(ingredients: Ingredient[]) {
21 | // for (let ingredient of ingredients) {
22 | // this.addIngredient(ingredient);
23 | // }
24 | this.ingredients.push(...ingredients);
25 | this.ingredientsChanged.emit(this.ingredients.slice());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/app/header/header.component.html:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-edit/shopping-edit.component.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Component,
3 | OnInit,
4 | ElementRef,
5 | ViewChild
6 | } from '@angular/core';
7 |
8 | import { Ingredient } from '../../shared/ingredient.model';
9 | import { ShoppingListService } from '../shopping-list.service';
10 |
11 | @Component({
12 | selector: 'app-shopping-edit',
13 | templateUrl: './shopping-edit.component.html',
14 | styleUrls: ['./shopping-edit.component.css']
15 | })
16 | export class ShoppingEditComponent implements OnInit {
17 | @ViewChild('nameInput') nameInputRef: ElementRef;
18 | @ViewChild('amountInput') amountInputRef: ElementRef;
19 |
20 | constructor(private slService: ShoppingListService) { }
21 |
22 | ngOnInit() {
23 | }
24 |
25 | onAddItem() {
26 | const ingName = this.nameInputRef.nativeElement.value;
27 | const ingAmount = this.amountInputRef.nativeElement.value;
28 | const newIngredient = new Ingredient(ingName, ingAmount);
29 | this.slService.addIngredient(newIngredient);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/app/shopping-list/shopping-edit/shopping-edit.component.html:
--------------------------------------------------------------------------------
1 |
32 |
--------------------------------------------------------------------------------
/src/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-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage'),
20 | reports: ['html', 'lcovonly'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
--------------------------------------------------------------------------------
/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { AppComponent } from './app.component';
3 |
4 | describe('AppComponent', () => {
5 | beforeEach(() => {
6 | TestBed.configureTestingModule({
7 | declarations: [
8 | AppComponent
9 | ],
10 | });
11 | TestBed.compileComponents();
12 | });
13 |
14 | it('should create the app', async(() => {
15 | const fixture = TestBed.createComponent(AppComponent);
16 | const app = fixture.debugElement.componentInstance;
17 | expect(app).toBeTruthy();
18 | }));
19 |
20 | it(`should have as title 'app works!'`, async(() => {
21 | const fixture = TestBed.createComponent(AppComponent);
22 | const app = fixture.debugElement.componentInstance;
23 | expect(app.title).toEqual('app works!');
24 | }));
25 |
26 | it('should render title in a h1 tag', async(() => {
27 | const fixture = TestBed.createComponent(AppComponent);
28 | fixture.detectChanges();
29 | const compiled = fixture.debugElement.nativeElement;
30 | expect(compiled.querySelector('h1').textContent).toContain('app works!');
31 | }));
32 | });
33 |
--------------------------------------------------------------------------------
/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 |
4 | import { RecipesComponent } from './recipes/recipes.component';
5 | import { ShoppingListComponent } from './shopping-list/shopping-list.component';
6 | import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component';
7 | import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
8 | import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component';
9 |
10 | const appRoutes: Routes = [
11 | { path: '', redirectTo: '/recipes', pathMatch: 'full' },
12 | { path: 'recipes', component: RecipesComponent, children: [
13 | { path: '', component: RecipeStartComponent },
14 | { path: 'new', component: RecipeEditComponent },
15 | { path: ':id', component: RecipeDetailComponent },
16 | { path: ':id/edit', component: RecipeEditComponent },
17 | ] },
18 | { path: 'shopping-list', component: ShoppingListComponent },
19 | ];
20 |
21 | @NgModule({
22 | imports: [RouterModule.forRoot(appRoutes)],
23 | exports: [RouterModule]
24 | })
25 | export class AppRoutingModule {
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-detail/recipe-detail.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ActivatedRoute, Params, Router } from '@angular/router';
3 |
4 | import { Recipe } from '../recipe.model';
5 | import { RecipeService } from '../recipe.service';
6 |
7 | @Component({
8 | selector: 'app-recipe-detail',
9 | templateUrl: './recipe-detail.component.html',
10 | styleUrls: ['./recipe-detail.component.css']
11 | })
12 | export class RecipeDetailComponent implements OnInit {
13 | recipe: Recipe;
14 | id: number;
15 |
16 | constructor(private recipeService: RecipeService,
17 | private route: ActivatedRoute,
18 | private router: Router) {
19 | }
20 |
21 | ngOnInit() {
22 | this.route.params
23 | .subscribe(
24 | (params: Params) => {
25 | this.id = +params['id'];
26 | this.recipe = this.recipeService.getRecipe(this.id);
27 | }
28 | );
29 | }
30 |
31 | onAddToShoppingList() {
32 | this.recipeService.addIngredientsToShoppingList(this.recipe.ingredients);
33 | }
34 |
35 | onEditRecipe() {
36 | this.router.navigate(['edit'], {relativeTo: this.route});
37 | // this.router.navigate(['../', this.id, 'edit'], {relativeTo: this.route});
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe.service.ts:
--------------------------------------------------------------------------------
1 | import { EventEmitter, Injectable } from '@angular/core';
2 |
3 | import { Recipe } from './recipe.model';
4 | import { Ingredient } from '../shared/ingredient.model';
5 | import { ShoppingListService } from '../shopping-list/shopping-list.service';
6 |
7 | @Injectable()
8 | export class RecipeService {
9 | recipeSelected = new EventEmitter();
10 |
11 | private recipes: Recipe[] = [
12 | new Recipe(
13 | 'Tasty Schnitzel',
14 | 'A super-tasty Schnitzel - just awesome!',
15 | 'https://upload.wikimedia.org/wikipedia/commons/7/72/Schnitzel.JPG',
16 | [
17 | new Ingredient('Meat', 1),
18 | new Ingredient('French Fries', 20)
19 | ]),
20 | new Recipe('Big Fat Burger',
21 | 'What else you need to say?',
22 | 'https://upload.wikimedia.org/wikipedia/commons/b/be/Burger_King_Angus_Bacon_%26_Cheese_Steak_Burger.jpg',
23 | [
24 | new Ingredient('Buns', 2),
25 | new Ingredient('Meat', 1)
26 | ])
27 | ];
28 |
29 | constructor(private slService: ShoppingListService) {}
30 |
31 | getRecipes() {
32 | return this.recipes.slice();
33 | }
34 |
35 | getRecipe(index: number) {
36 | return this.recipes[index];
37 | }
38 |
39 | addIngredientsToShoppingList(ingredients: Ingredient[]) {
40 | this.slService.addIngredients(ingredients);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/app/recipes/recipe-detail/recipe-detail.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
![{{ recipe.name }}]()
8 |
9 |
10 |
11 |
12 |
{{ recipe.name }}
13 |
14 |
15 |
16 |
17 |
20 |
25 |
30 |
31 |
32 |
33 |
34 |
35 | {{ recipe.description }}
36 |
37 |
38 |
39 |
40 |
41 | -
44 | {{ ingredient.name }} - {{ ingredient.amount }}
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AngularJs
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.2.1.
4 |
5 | # Concepts used in this project
6 | Developed modern, complex, responsive and scalable web applications with Angular6
7 | 1. Custom directives
8 | 2. Databinding
9 | 3. Routing and handling Navigation
10 | 4. Pipes
11 | 5. Dependency Injection: communicating data between components
12 | 6. Modules creation
13 | 7. Observables
14 |
15 |
16 | ## Development server
17 |
18 | 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.
19 |
20 | ## Code scaffolding
21 |
22 | 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`.
23 |
24 | ## Build
25 |
26 | 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.
27 |
28 | ## Running unit tests
29 |
30 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
31 |
32 | ## Running end-to-end tests
33 |
34 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
35 |
36 | ## Further help
37 |
38 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-js",
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": "^6.1.0",
15 | "@angular/common": "^6.1.0",
16 | "@angular/compiler": "^6.1.0",
17 | "@angular/core": "^6.1.0",
18 | "@angular/forms": "^6.1.0",
19 | "@angular/http": "^6.1.0",
20 | "@angular/platform-browser": "^6.1.0",
21 | "@angular/platform-browser-dynamic": "^6.1.0",
22 | "@angular/router": "^6.1.0",
23 | "bootstrap": "^3.3.7",
24 | "core-js": "^2.5.4",
25 | "rxjs": "~6.2.0",
26 | "zone.js": "~0.8.26"
27 | },
28 | "devDependencies": {
29 | "@angular-devkit/build-angular": "~0.8.0",
30 | "@angular/cli": "~6.2.1",
31 | "@angular/compiler-cli": "^6.1.0",
32 | "@angular/language-service": "^6.1.0",
33 | "@types/jasmine": "~2.8.8",
34 | "@types/jasminewd2": "~2.0.3",
35 | "@types/node": "~8.9.4",
36 | "codelyzer": "~4.3.0",
37 | "jasmine-core": "~2.99.1",
38 | "jasmine-spec-reporter": "~4.2.1",
39 | "karma": "~3.0.0",
40 | "karma-chrome-launcher": "~2.2.0",
41 | "karma-coverage-istanbul-reporter": "~2.0.1",
42 | "karma-jasmine": "~1.1.2",
43 | "karma-jasmine-html-reporter": "^0.2.2",
44 | "protractor": "~5.4.0",
45 | "ts-node": "~7.0.0",
46 | "tslint": "~5.11.0",
47 | "typescript": "~2.9.2"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/app/app.module.ts:
--------------------------------------------------------------------------------
1 | import { BrowserModule } from '@angular/platform-browser';
2 | import { NgModule } from '@angular/core';
3 | import { FormsModule } from '@angular/forms';
4 | import { HttpModule } from '@angular/http';
5 |
6 | import { AppComponent } from './app.component';
7 | import { HeaderComponent } from './header/header.component';
8 | import { RecipesComponent } from './recipes/recipes.component';
9 | import { RecipeListComponent } from './recipes/recipe-list/recipe-list.component';
10 | import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
11 | import { RecipeItemComponent } from './recipes/recipe-list/recipe-item/recipe-item.component';
12 | import { ShoppingListComponent } from './shopping-list/shopping-list.component';
13 | import { ShoppingEditComponent } from './shopping-list/shopping-edit/shopping-edit.component';
14 | import { DropdownDirective } from './shared/dropdown.directive';
15 | import { ShoppingListService } from './shopping-list/shopping-list.service';
16 | import { AppRoutingModule } from './app-routing.module';
17 | import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component';
18 | import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component';
19 |
20 | @NgModule({
21 | declarations: [
22 | AppComponent,
23 | HeaderComponent,
24 | RecipesComponent,
25 | RecipeListComponent,
26 | RecipeDetailComponent,
27 | RecipeItemComponent,
28 | ShoppingListComponent,
29 | ShoppingEditComponent,
30 | DropdownDirective,
31 | RecipeStartComponent,
32 | RecipeEditComponent
33 | ],
34 | imports: [
35 | BrowserModule,
36 | FormsModule,
37 | HttpModule,
38 | AppRoutingModule
39 | ],
40 | providers: [ShoppingListService],
41 | bootstrap: [AppComponent]
42 | })
43 | export class AppModule { }
44 |
--------------------------------------------------------------------------------
/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/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Web Animations `@angular/platform-browser/animations`
51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
53 | **/
54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
55 |
56 | /**
57 | * By default, zone.js will patch all possible macroTask and DomEvents
58 | * user can disable parts of macroTask/DomEvents patch by setting following flags
59 | */
60 |
61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
64 |
65 | /*
66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
68 | */
69 | // (window as any).__Zone_enable_cross_context_check = true;
70 |
71 | /***************************************************************************************************
72 | * Zone JS is required by default for Angular itself.
73 | */
74 | import 'zone.js/dist/zone'; // Included with Angular CLI.
75 |
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
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-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-redundant-jsdoc": true,
69 | "no-shadowed-variable": true,
70 | "no-string-literal": false,
71 | "no-string-throw": true,
72 | "no-switch-case-fall-through": true,
73 | "no-trailing-whitespace": true,
74 | "no-unnecessary-initializer": true,
75 | "no-unused-expression": true,
76 | "no-use-before-declare": true,
77 | "no-var-keyword": true,
78 | "object-literal-sort-keys": false,
79 | "one-line": [
80 | true,
81 | "check-open-brace",
82 | "check-catch",
83 | "check-else",
84 | "check-whitespace"
85 | ],
86 | "prefer-const": true,
87 | "quotemark": [
88 | true,
89 | "single"
90 | ],
91 | "radix": true,
92 | "semicolon": [
93 | true,
94 | "always"
95 | ],
96 | "triple-equals": [
97 | true,
98 | "allow-null-check"
99 | ],
100 | "typedef-whitespace": [
101 | true,
102 | {
103 | "call-signature": "nospace",
104 | "index-signature": "nospace",
105 | "parameter": "nospace",
106 | "property-declaration": "nospace",
107 | "variable-declaration": "nospace"
108 | }
109 | ],
110 | "unified-signatures": true,
111 | "variable-name": false,
112 | "whitespace": [
113 | true,
114 | "check-branch",
115 | "check-decl",
116 | "check-operator",
117 | "check-separator",
118 | "check-type"
119 | ],
120 | "no-output-on-prefix": true,
121 | "use-input-property-decorator": true,
122 | "use-output-property-decorator": true,
123 | "use-host-property-decorator": true,
124 | "no-input-rename": true,
125 | "no-output-rename": true,
126 | "use-life-cycle-interface": true,
127 | "use-pipe-transform-interface": true,
128 | "component-class-suffix": true,
129 | "directive-class-suffix": true
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "angularJs": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {},
12 | "targets": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/angularJs",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": "src/polyfills.ts",
20 | "tsConfig": "src/tsconfig.app.json",
21 | "assets": [
22 | "src/favicon.ico",
23 | "src/assets"
24 | ],
25 | "styles": [
26 | "node_modules\\bootstrap\\dist\\css\\bootstrap.min.css",
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 | "extractCss": true,
43 | "namedChunks": false,
44 | "aot": true,
45 | "extractLicenses": true,
46 | "vendorChunk": false,
47 | "buildOptimizer": true
48 | }
49 | }
50 | },
51 | "serve": {
52 | "builder": "@angular-devkit/build-angular:dev-server",
53 | "options": {
54 | "browserTarget": "angularJs:build"
55 | },
56 | "configurations": {
57 | "production": {
58 | "browserTarget": "angularJs:build:production"
59 | }
60 | }
61 | },
62 | "extract-i18n": {
63 | "builder": "@angular-devkit/build-angular:extract-i18n",
64 | "options": {
65 | "browserTarget": "angularJs:build"
66 | }
67 | },
68 | "test": {
69 | "builder": "@angular-devkit/build-angular:karma",
70 | "options": {
71 | "main": "src/test.ts",
72 | "polyfills": "src/polyfills.ts",
73 | "tsConfig": "src/tsconfig.spec.json",
74 | "karmaConfig": "src/karma.conf.js",
75 | "styles": [
76 | "src/styles.css"
77 | ],
78 | "scripts": [],
79 | "assets": [
80 | "src/favicon.ico",
81 | "src/assets"
82 | ]
83 | }
84 | },
85 | "lint": {
86 | "builder": "@angular-devkit/build-angular:tslint",
87 | "options": {
88 | "tsConfig": [
89 | "src/tsconfig.app.json",
90 | "src/tsconfig.spec.json"
91 | ],
92 | "exclude": [
93 | "**/node_modules/**"
94 | ]
95 | }
96 | }
97 | }
98 | },
99 | "angularJs-e2e": {
100 | "root": "e2e/",
101 | "projectType": "application",
102 | "targets": {
103 | "e2e": {
104 | "builder": "@angular-devkit/build-angular:protractor",
105 | "options": {
106 | "protractorConfig": "e2e/protractor.conf.js",
107 | "devServerTarget": "angularJs:serve"
108 | },
109 | "configurations": {
110 | "production": {
111 | "devServerTarget": "angularJs:serve:production"
112 | }
113 | }
114 | },
115 | "lint": {
116 | "builder": "@angular-devkit/build-angular:tslint",
117 | "options": {
118 | "tsConfig": "e2e/tsconfig.e2e.json",
119 | "exclude": [
120 | "**/node_modules/**"
121 | ]
122 | }
123 | }
124 | }
125 | }
126 | },
127 | "defaultProject": "angularJs"
128 | }
--------------------------------------------------------------------------------