| @@ -5,14 +5,9 @@ import { HttpClientModule } from '@angular/common/http'; | |||||
| import { AppComponent } from './app.component'; | import { AppComponent } from './app.component'; | ||||
| import { AppRoutingModule } from './app-routing.module'; | import { AppRoutingModule } from './app-routing.module'; | ||||
| import { AuthGuard } from './auth/auth-guard.service'; | |||||
| import { AuthModule } from './auth/auth.module'; | |||||
| import { AuthService } from './auth/auth.service'; | |||||
| import { DataStorageService } from './shared/data-storage.service'; | |||||
| import { RecipeService } from './recipes/recipe.service'; | |||||
| import { SharedModule } from './shared/shared.module'; | import { SharedModule } from './shared/shared.module'; | ||||
| import { ShoppingListModule } from './shopping-list/shopping-list.module'; | import { ShoppingListModule } from './shopping-list/shopping-list.module'; | ||||
| import { ShoppingListService } from './shopping-list/shopping-list.service'; | |||||
| import { AuthModule } from './auth/auth.module'; | |||||
| import { CoreModule } from './core/core.module'; | import { CoreModule } from './core/core.module'; | ||||
| @NgModule({ | @NgModule({ | ||||
| @@ -29,12 +24,6 @@ import { CoreModule } from './core/core.module'; | |||||
| AuthModule, | AuthModule, | ||||
| CoreModule | CoreModule | ||||
| ], | ], | ||||
| providers: [ | |||||
| ShoppingListService, | |||||
| RecipeService, | |||||
| DataStorageService, | |||||
| AuthService, | |||||
| AuthGuard], | |||||
| bootstrap: [AppComponent] | bootstrap: [AppComponent] | ||||
| }) | }) | ||||
| export class AppModule { } | export class AppModule { } | ||||
| @@ -4,6 +4,10 @@ import { HeaderComponent } from "./header/header.component"; | |||||
| import { HomeComponent } from "./home/home.component"; | import { HomeComponent } from "./home/home.component"; | ||||
| import { SharedModule } from "../shared/shared.module"; | import { SharedModule } from "../shared/shared.module"; | ||||
| import { AppRoutingModule } from "../app-routing.module"; | import { AppRoutingModule } from "../app-routing.module"; | ||||
| import { ShoppingListService } from "../shopping-list/shopping-list.service"; | |||||
| import { RecipeService } from "../recipes/recipe.service"; | |||||
| import { DataStorageService } from "../shared/data-storage.service"; | |||||
| import { AuthService } from "../auth/auth.service"; | |||||
| @NgModule({ | @NgModule({ | ||||
| declarations: [ | declarations: [ | ||||
| @@ -17,6 +21,12 @@ import { AppRoutingModule } from "../app-routing.module"; | |||||
| exports: [ | exports: [ | ||||
| AppRoutingModule, | AppRoutingModule, | ||||
| HeaderComponent | HeaderComponent | ||||
| ] | |||||
| ], | |||||
| providers: [ | |||||
| ShoppingListService, | |||||
| RecipeService, | |||||
| DataStorageService, | |||||
| AuthService | |||||
| ], | |||||
| }) | }) | ||||
| export class CoreModule {} | export class CoreModule {} | ||||
| @@ -10,12 +10,12 @@ | |||||
| <li routerLinkActive="active"><a routerLink="/shopping-list">Shopping List</a></li> | <li routerLinkActive="active"><a routerLink="/shopping-list">Shopping List</a></li> | ||||
| </ul> | </ul> | ||||
| <ul class="nav navbar-nav navbar-right"> | <ul class="nav navbar-nav navbar-right"> | ||||
| <ng-template [ngIf]="!authService.isAuthenticated()"> | |||||
| <ng-template [ngIf]="!isAuthenticated()"> | |||||
| <li><a routerLink="/signup">Register</a></li> | <li><a routerLink="/signup">Register</a></li> | ||||
| <li><a routerLink="/signin">Login</a></li> | <li><a routerLink="/signin">Login</a></li> | ||||
| </ng-template> | </ng-template> | ||||
| <li><a style="cursor: pointer;" (click)="onLogout()" *ngIf="authService.isAuthenticated()">Logout</a></li> | |||||
| <li class="dropdown" appDropdown *ngIf="authService.isAuthenticated()"> | |||||
| <li><a style="cursor: pointer;" (click)="onLogout()" *ngIf="isAuthenticated()">Logout</a></li> | |||||
| <li class="dropdown" appDropdown *ngIf="isAuthenticated()"> | |||||
| <a style="cursor: pointer;" class="dropdown-toggle" role="button">Manage <span class="caret"></span></a> | <a style="cursor: pointer;" class="dropdown-toggle" role="button">Manage <span class="caret"></span></a> | ||||
| <ul class="dropdown-menu"> | <ul class="dropdown-menu"> | ||||
| <li><a style="cursor: pointer;" (click)="onSaveData()">Save</a></li> | <li><a style="cursor: pointer;" (click)="onSaveData()">Save</a></li> | ||||
| @@ -25,4 +25,8 @@ export class HeaderComponent { | |||||
| onLogout() { | onLogout() { | ||||
| this.authService.logout(); | this.authService.logout(); | ||||
| } | } | ||||
| isAuthenticated() { | |||||
| return this.authService.isAuthenticated(); | |||||
| } | |||||
| } | } | ||||
| @@ -60,7 +60,7 @@ | |||||
| <div class="col-xs-12" formArrayName="ingredients"> | <div class="col-xs-12" formArrayName="ingredients"> | ||||
| <div | <div | ||||
| class="row" | class="row" | ||||
| *ngFor="let ingredientCtrl of recipeForm.get('ingredients').controls; let i = index" | |||||
| *ngFor="let ingredientCtrl of getIngredientControls(); let i = index" | |||||
| [formGroupName]="i" | [formGroupName]="i" | ||||
| style="margin-top: 10px;"> | style="margin-top: 10px;"> | ||||
| <div class="col-xs-8"> | <div class="col-xs-8"> | ||||
| @@ -88,4 +88,9 @@ export class RecipeEditComponent implements OnInit { | |||||
| 'ingredients': recipeIngredients | 'ingredients': recipeIngredients | ||||
| }); | }); | ||||
| } | } | ||||
| getIngredientControls() { | |||||
| return (<FormArray>this.recipeForm.get('ingredients')).controls; | |||||
| } | |||||
| } | } | ||||
| @@ -18,6 +18,9 @@ const recipesRoutes: Routes = [ | |||||
| @NgModule({ | @NgModule({ | ||||
| imports: [RouterModule.forChild(recipesRoutes)], | imports: [RouterModule.forChild(recipesRoutes)], | ||||
| exports: [RouterModule] | |||||
| exports: [RouterModule], | |||||
| providers: [ | |||||
| AuthGuard | |||||
| ] | |||||
| }) | }) | ||||
| export class RecipesRoutingModule {} | export class RecipesRoutingModule {} | ||||