Skip to content

Instantly share code, notes, and snippets.

@finzaiko
Last active January 4, 2018 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save finzaiko/32d670086a4690354280c0889dc5e5bf to your computer and use it in GitHub Desktop.
Save finzaiko/32d670086a4690354280c0889dc5e5bf to your computer and use it in GitHub Desktop.
Angular 2 plus - Membuat Komponen

Dalam contoh ini kita membuat komponen/halaman about

1. Buat file typescript baru about.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'about',
  templateUrl: 'app/pages/about/about.html',
  styleUrls:  ['app/pages/about/about.css']
})
export class AboutComponent { }

2. Buat file html about.html

<div class="starter-template">
    <h1>About</h1>
    <p class="lead">This is about page.</p>
</div>

3. Buat file css about.css

h1{
    color: green;
}

4. Daftarkan komponen di NgModule

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { AboutComponent } from './pages/about/about.component';

@NgModule({
  imports: [
    BrowserModule,
  ],
  declarations: [
    AppComponent,
    AboutComponent
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Membuat Komponen Menggunakan CLI

ng generate component my-new-component
atau:
ng g component my-new-component # using the alias
atau:
ng g component feature/new-cmp  // membuat component didalam folder (contoh feature)

Resources :
https://github.com/angular/angular-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment