2 components
what is component in angular?
A component in angular is a class with a template and a decorator..
in simple a componet in angular composed of template , class , decorator
template defines the user interface, contains the HTMl, directives and
data bindings
class contains the code required for the template..
a class in ang contain properties and methods..,
properties contains data for the view template,
methods contains logic for the view..
decoratator adds meta data to the class making it an angular component
component decoretor provided by angular to use decorator we have to import from angular
import { Component} from "@angular/core";
@Component({
selector:'myapp',
tempalte:'xx'; //back ticks
})
export class AppComponent{ /
/export keyword allows this class to exported so other componets to imported and used
name: string ="Angular";
//property:datatype=value
}
import { Component } from '@angular/core'; // 2nd load component for decorator
@Component({ //3rd add decorator
selector:'app-root',
template:`hi {{title}}` //back ticks used when html data is more than 1 line
})
export class AppComponent{ // 1st create class appcmpt and add export
title :string = 'angular';
//property:datatype = value;
}
Comments
Post a Comment