Angular Custom Components _angular

Source: Internet
Author: User
Tags export class

Custom Component Http://www.ngui.cc/news/show-103.html

In angular, we can create custom components by Component adorners and custom component classes. Basic knowledge defines the meta information of a component

In angular, we can use the Component adorner to define meta information for a component:

@Component ({
  
  Template: ' 
Defining component Classes
Export class Appcomponent  {
  name = ' angular '; 
}
Defining data interfaces

An interface in typescript is a very flexible concept that is often used to describe object shape (shape), in addition to being able to abstract part of a class's behavior.

Interface person {
  name:string;
  Age:number;
Let Semlinker:person = {
  name: ' Semlinker ',
  age:31};
Custom Component Example Create Usercomponent component
@Component ({
    selector: ' Sl-user ',
    Template: '
    
Export class Usercomponent {
    name = ' Semlinker ';
    Address = {
        province: ' Fujian ', City
        : ' Xiamen '};
Declaring Usercomponent Components
. Import {usercomponent} from './user.component ';
@NgModule ({
  imports:      [browsermodule],
  declarations: [Appcomponent, Usercomponent],
  Bootstrap :    [Appcomponent]
Export class Appmodule {}
Using the Usercomponent component
Import {Component} from ' @angular/core ';
@Component ({
  selector: ' My-app ',
  Template: '
    <sl-user></sl-user> '
  ,
Export class Appcomponent {}
Initializing data using constructors
Export class Usercomponent {
    name:string;
    
Constructor () {
            
this.address = {
            province: ' Fujian ', City
            : ' Xiamen '
    }}
}
Interface uses an example to define an address interface
interface Address {province:string;
    city:string;
}
Using the Address interface
Export class Usercomponent {
    name:string;
    address:address; // ... }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.