美文网首页
@Component装饰器

@Component装饰器

作者: JamesSawyer | 来源:发表于2017-07-04 00:54 被阅读18次

这个装饰器是 DirectiveDecorator 的一个子类,装饰器名为 ComponentDecorator

其接口定义如下:

export interface ComponentDecorator {
    /**
     * @whatItDoes 标记一个类为 Angular 组件,并收集组件配置元数据
     *
     * @howToUse
     * Angular组件是指令的子集,和指令不同的是
     * 组件永远都有一个模版,只有组件才能实例化模版中的元素.
     *
     * 除了配置元数据,组件可以通过声明周期钩子来控制它运行时的行为
     *
     * **元数据属性:**
     *
     * * **animations** - 组件的动画列表 list of animations of this component
     * * **changeDetection** - 组件的变化检测策略 change detection strategy used by this component
     * * **encapsulation** - 组件的样式封装策略 style encapsulation strategy used by this component
     * * **entryComponents** - 动态插入到这个组件视图的一组组件 list of components that are dynamically inserted into the view of this component
     * * **exportAs** - 在模板中导出组件实例的名称 name under which the component instance is exported in a template
     * * **host** - 类属性的映射,用于绑定事件,属性和特性 相当于 HostBinding 或者 HostListener , map of class property to host element bindings for events, properties and
     *   attributes
     * * **inputs** - 类属性名称的列表, 以数据绑定作为组件输入 list of class property names to data-bind as component inputs
     * * **interpolation** - 此组件的模板中使用的自定义插值标记 custom interpolation markers used in this component's template
     * * **moduleId** - ES/CommonJS module id of the file in which this component is defined
     * * **outputs** - 暴露给外界,以便外界订阅的类属性列表 list of class property names that expose output events that others can
     *   subscribe to
     * * **providers** - 此组件及其子级可用的提供商列表 list of providers available to this component and its children
     * * **queries** -  可以插入到组件中的查询配置 configure queries that can be injected into the component
     * * **selector** - css selector that identifies this component in a template
     * * **styleUrls** - list of urls to stylesheets to be applied to this component's view
     * * **styles** - inline-defined styles to be applied to this component's view
     * * **template** - inline-defined template for the view
     * * **templateUrl** - url to an external file containing a template for the view
     * * **viewProviders** - 此组件及其视图子级可用的提供商列表 list of providers available to this component and its view children
 }

组件继承指令:

export interface Component extends Directive {
    /**
     * Defines the used change detection strategy.
     * 定义使用的变化检测策略
     * 当一个组件被实例化时, angular创建一个变更检测器, 它负责
传播组件的绑定。
     *"changeDetection" 属性的定义是, 是否每次都检查更改检测
或者只有当组件告诉什么时候去检测变化
     */
    changeDetection?: ChangeDetectionStrategy;

     # 定义一组只对其视图子DOM可用的可注入的对象
    viewProviders?: Provider[];

     # 使用 SystemJS 才用,现在一般很少使用了
    moduleId?: string;

    templateUrl?: string;
    template?: string;

    styleUrls?: string[];
    styles?: string[];

    # angular 动画库的一种内联写法
    animations?: any[];

    # 指定模版和样式封装方式,基本不用
    encapsulation?: ViewEncapsulation;

    # 重写默认的封装开始和结束符( `{{` and `}}`) 基本不用
    interpolation?: [string, string];

   # 定义其它组件在本组件被编译时,其它组件也被编译,一般用于动态插入组件的情况 用的比较多

    # Angular 将创建一个 {@link ComponentFactory} 并且存储在   {@link ComponentFactoryResolver}上
    entryComponents?: Array<Type<any> | any[]>;
}

export declare const Component: ComponentDecorator;

通过上面的注释可以看出组件原信息的使用频率

相关文章

  • angular组件

    Angular组件 @Component装饰器 @Component装饰器用于标示这个类是组件类 selector...

  • @Component装饰器

    这个装饰器是 DirectiveDecorator 的一个子类,装饰器名为 ComponentDecorator ...

  • Java常用设计模式

    设计模式 装饰器模式 定义接口public interface Component { void doSom...

  • 01. 架构

    模块(Module) Angular模块都是一个带有@NgModule装饰器的类, 组件(Component) 在...

  • Angular组件介绍

    1.背景介绍 Angular组件的必备元素 1.组件元数据装饰器:@Component() 告诉angular如何...

  • vue-class-component

    vue-class-component 是尤大大推出的vue对typescript支持的装饰器(库) vue-c...

  • vue-class-component 使用说明

    vue-class-component 为了定义带有装饰器风格的Vue组件,如果使用Babel转换,必须使用bab...

  • ionic2- 导航页面

    Page页面在angular语法上也是一个组件,所以同样有@Component装饰器,但是其selector属性可...

  • Angular2 组件的使用

    创建组件需要三步: 1.从 @angular/core 引入 Component 装饰器 2.创建一个类,并用 @...

  • 小程序(三)—— modal组件封装

    Component构造器 Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性...

网友评论

      本文标题:@Component装饰器

      本文链接:https://www.haomeiwen.com/subject/jccthxtx.html