Tuesday, October 4, 2016

Simple component angular 2




  • Components are simply directives that are always associated with a direct template
  • Component is nothing but a type script class
  • An Angular application is a tree of Angular components

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

@Component({
  selector: 'my-story',
  template: `
    <h3>{{story.name}}</h3>
    <h3 [innerText]="story.name"></h3>
    <div [style.color]="color">{{story.name}}</div>
    {{story| json}}
  `
})
export class StoryComponent {
  story = { id: 100, name: 'The Force Awakens' };
  color = 'blue';
}

Output


Note: We can also specify the template URL
@component({
selector :'my-story',
templateUrl:'app/somewhere.html'
})

No comments:

Post a Comment