Angular 2 for beginners, including app architecture, components, services, http and routing. Everything you need to build a much-more-than-basic app. Presented at SheCodes(tlv), May 2016.
selector: 'product', templateUrl: 'app/product/product.component.html' }) export class ProductComponent {} // parent component template <product></product> product my-store // generate new component > ng g c product
moduleId: module.id, selector: 'product', template: ` <h1>Hello World!</h1>` }) export class ProductComponent {} product // generate new component > ng g c product
@Component({ moduleId: module.id, selector: 'product', template: ` <h1>{{ title }}</h1>` }) export class ProductComponent { title = 'Hello World!'; } product // generate new component > ng g c product
} from '../services/product.service'; @Component({ moduleId: module.id, selector: 'product', templateUrl: 'product.component.html' }) export class ProductComponent { constructor(private productService: ProductService) { // do simple stuff } } The service needs to be provided
bootstrap } from '@angular/platform-browser-dynamic'; import { MyStoreComponent } from './app/'; import { ProductsService } from './app/products.service'; bootstrap(MyStoreComponent, [ProductsService]); service app provide
{ Routes, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router'; @Component({ moduleId: module.id, selector: 'my-store', templateUrl: 'my-store.component.html', directives: [ROUTER_DIRECTIVES], providers: [ROUTER_PROVIDERS] }) @Routes([ ]) export class MyStoreComponent { constructor(private router: Router) {} } Make sure you have all this when using Angular CLI