Skip to content

Instantly share code, notes, and snippets.

View smolkat's full-sized avatar
🏠
Working from home

Aditya Banerjee smolkat

🏠
Working from home
View GitHub Profile
@smolkat
smolkat / app-routing.module.ts
Created October 2, 2018 14:05
details route added
import { NgModule, Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes, Route } from '@angular/router';
import { ItemsComponent } from './items/items.component';
import { FavouritesComponent } from './favourites/favourites.component';
import { ItemDetailsComponent } from './item-details/item-details.component';
const routes: Routes = [
{path: 'items', component: ItemsComponent},
{path: 'favourites', component: FavouritesComponent},
@smolkat
smolkat / item.service.ts
Created October 2, 2018 14:02
angular service provides the items to other scripts
import { Injectable } from '@angular/core';
import { ITEMS } from './demo_items';
import { Item } from './item';
import { Observable, of } from 'rxjs';
import { TransactionsService } from './transactions.service';
@Injectable({
// at the root level, Angular creates a single, shared instance
// of ItemService and injects into any class that asks for it.
providedIn: 'root'
@smolkat
smolkat / item-details.component.ts
Created October 2, 2018 13:55
added the back function navigation
import { Component, OnInit, Input } from '@angular/core';
import { Item } from '../item';
import { ItemsComponent } from '../items/items.component';
import { ActivatedRoute } from '@angular/router';
import { Location } from '@angular/common';
import { ItemService } from '../item.service';
@Component({
selector: 'app-item-details',
templateUrl: './item-details.component.html',
@smolkat
smolkat / item-details.component.html
Created October 2, 2018 13:54
back button added details view
<!-- displays the details -->
<div *ngIf='item'>
<h3>Details</h3>
<label>This is a </label>{{item.name}}<br>
<label>Its value is </label>{{item.value}}<br>
<label>{{item.info}}</label>
</div>
<div>
<button (click)="goBack()">back</button>
</div>
@smolkat
smolkat / favourites.component.html
Created October 2, 2018 13:52
favourites view
<div>
<h3>Favourite Items</h3>
<div class="grid grid-pad">
<a *ngFor="let item of items" class="col-1-4"
routerLink="/details/{{item.id}}">
<div class="module item">
<h4>{{item.name}}</h4>
</div>
</a>
</div>
@smolkat
smolkat / items.component.html
Last active October 2, 2018 13:36
added routerLink to the items in place of onClick() method
<ul class="items">
<li *ngFor='let item of items'>
<a routerLink="/details/{{item.id}}">
<span class="badge">{{item.id}}</span>
{{item.name | uppercase}}
<span class="value">{{item.value}}</span>
</a>
</li>
</ul>
@smolkat
smolkat / app-routing.module.ts
Last active October 2, 2018 14:05
add default path and favourites route
import { NgModule, Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes, Route } from '@angular/router';
import { ItemsComponent } from './items/items.component';
import { FavouritesComponent } from './favourites/favourites.component';
const routes: Routes = [
{path: 'items', component: ItemsComponent},
{path: 'favourites', component: FavouritesComponent},
{path: '', redirectTo: '/favourites', pathMatch: 'full'},
@smolkat
smolkat / favourites.component.ts
Created September 28, 2018 17:30
favourite listing logic is here
import { Component, OnInit } from '@angular/core';
import { ItemService } from '../item.service';
import { Item } from '../item';
@Component({
selector: 'app-favourites',
templateUrl: './favourites.component.html',
styleUrls: ['./favourites.component.css']
})
export class FavouritesComponent implements OnInit {
@smolkat
smolkat / favourites.component.html
Created September 28, 2018 17:28
template of favourites
<h3>Favourite Items</h3>
<div class="grid grid-pad">
<a *ngFor="let item of items" class="col-1-4">
<div class="module item">
<h4>{{item.name}}</h4>
</div>
</a>
</div>
@smolkat
smolkat / app-routing.module.ts
Created September 27, 2018 09:07
router module for the app, has only one route to items
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes, Route } from '@angular/router';
import { ItemsComponent } from './items/items.component';
const routes: Routes = [{
path: 'items',
component: ItemsComponent
}];
@NgModule({