Skip to content

Instantly share code, notes, and snippets.

View sonicoder86's full-sized avatar

Gábor Soós sonicoder86

View GitHub Profile
@sonicoder86
sonicoder86 / component-relative-paths-webpack.ts
Created June 9, 2016 10:39
Component-Relative paths in Angular 2 for Webpack
import { Component } from '@angular/core';
import headerTemplate from './header.component.html';
import headerStyle from './header.component.css';
@Component({
selector: 'my-app',
template: headerTemplate,
styles: [headerStyle]
})
export class HeaderComponent implements OnInit {
@sonicoder86
sonicoder86 / app.component.ts
Last active June 24, 2016 06:52
Upgrading to the new Angular 2 router - part 1
// components/app/app.component.ts
import { Component } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES } from '@angular/router-deprected';
import { HeroesComponent } from './components/heroes/heroes.component';
import { HeroDetailComponent } from '../hero-detail/hero-detail.component';
@RouteConfig([
{
path: '/',
@sonicoder86
sonicoder86 / routes.ts
Created June 24, 2016 06:53
Upgrading to the new Angular 2 router - part 2
// routes.ts
import { provideRouter, RouterConfig } from '@angular/router';
import { HeroesComponent } from './components/heroes/heroes.component';
import { HeroDetailComponent } from './components/hero-detail/hero-detail.component';
export const appRoutes: RouterConfig = [
{ path: '', component: HeroesComponent, terminal: true },
{ path: 'detail/:id', component: HeroDetailComponent }
];
@sonicoder86
sonicoder86 / main.ts
Created June 24, 2016 10:48
Upgrading to the new Angular 2 router - part 3
// main.ts
import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
import { AppComponent } from './components/app/app.component';
bootstrap(AppComponent, [
ROUTER_PROVIDERS
]);
@sonicoder86
sonicoder86 / main.ts
Created June 24, 2016 10:49
Upgrading to the new Angular 2 router - part 4
// main.ts
import { APP_ROUTER_PROVIDER } from './routes';
import { AppComponent } from './components/app/app.component';
bootstrap(AppComponent, [
APP_ROUTER_PROVIDER
]);
@sonicoder86
sonicoder86 / routes.html
Created June 24, 2016 10:54
Upgrading to the new Angular 2 router - part 5
<a [routerLink]="['/Heroes']">Heroes</a>
<a [routerLink]="['/HeroDetail', { id: 1 }]">Captain America</a>
@sonicoder86
sonicoder86 / routes.html
Created June 24, 2016 10:55
Upgrading to the new Angular 2 router - part 6
<a [routerLink]="['']">Heroes</a>
<a [routerLink]="['detail', 1]">Captain America</a>
@sonicoder86
sonicoder86 / redirect.ts
Created June 24, 2016 10:56
Upgrading to the new Angular 2 router - part 7
// navigates to Captain America's page
this.router.navigate(['detail', 1]);
@sonicoder86
sonicoder86 / hero-detail.component.ts
Created June 24, 2016 10:56
Upgrading to the new Angular 2 router - part 8
// components/hero-detail/hero-detail.component.ts
import { Component, OnInit } from '@angular/core';
import { RouteParams } from '@angular/router-deprected';
import { HeroService } from '../../services/hero/hero.service'
@Component({ ... })
export class HeroDetailComponent implements OnInit {
constructor(private params: RouteParams, private heroService: HeroService) {}
@sonicoder86
sonicoder86 / hero-detail.component.ts
Created June 24, 2016 10:58
Upgrading to the new Angular 2 router - part 9
// components/hero-detail/hero-detail.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HeroService } from '../../services/hero/hero.service'
@Component({ ... })
export class HeroDetailComponent implements OnInit {
constructor(private route: ActivatedRoute, private heroService: HeroService) {}