Angular应用里input字段后面的_ngcontent-hqi是什么含义

简介: Angular应用里input字段后面的_ngcontent-hqi是什么含义

我们打开Angular应用,在Chrome开发者工具的Elements面板里可以看到控件被自动加上了形如下图_ngcontent-hqi-c18这种属性,其中hqi为三位的app id,c18为Componentid.image.pngimage.png

/**
     * @param {?} eventManager
     * @param {?} sharedStylesHost
     * @param {?} component
     * @param {?} appId
     */
    constructor(eventManager, sharedStylesHost, component, appId) {
        super(eventManager);
        this.component = component;
        /** @type {?} */
        const styles = flattenStyles(appId + '-' + component.id, component.styles, []);
        sharedStylesHost.addStyles(styles);
        this.contentAttr = shimContentAttribute(appId + '-' + component.id);
        this.hostAttr = shimHostAttribute(appId + '-' + component.id);
    }

image.pngimage.png

这些属性的字符串拼接在这里完成:

/** @type {?} */
const COMPONENT_REGEX = /%COMP%/g;
/** @type {?} */
const NG_DEV_MODE = typeof ngDevMode === 'undefined' || !!ngDevMode;
/** @type {?} */
const COMPONENT_VARIABLE = '%COMP%';
/** @type {?} */
const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
/** @type {?} */
const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
/**
 * @param {?} componentShortId
 * @return {?}
 */
function shimContentAttribute(componentShortId) {
    return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
}
/**
 * @param {?} componentShortId
 * @return {?}
 */
function shimHostAttribute(componentShortId) {
    return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
}

image.png

相关文章
|
JavaScript
Angular 项目中 angular.json builder 字段的可选项介绍
Angular 项目中 angular.json builder 字段的可选项介绍
|
JSON 数据格式 索引
Angular 里使用嵌套 Form 的步骤
Angular 里使用嵌套 Form 的步骤
|
5月前
|
编译器 API 开发者
Angular Component ɵcmp 属性的含义和使用场合介绍
Angular Component ɵcmp 属性的含义和使用场合介绍
|
5月前
|
JavaScript 前端开发 开发工具
Angular 项目中一个 index.d.ts 文件的具体例子介绍
Angular 项目中一个 index.d.ts 文件的具体例子介绍
|
开发者
Angular 某些版本号中 0-next.0 的含义
Angular 某些版本号中 0-next.0 的含义
|
开发者
关于 Angular 里 module 和 Component 包含粒度的一个讨论
关于 Angular 里 module 和 Component 包含粒度的一个讨论
Angular InjectionToken APP_INITIALIZER multi 标志位不同值的情况讨论
Angular InjectionToken APP_INITIALIZER multi 标志位不同值的情况讨论
angular定义数组的三种方式
angular定义数组的三种方式
509 0
|
Web App开发 开发者
Angular应用里input字段后面的_ngcontent-hqi是什么含义
Angular应用里input字段后面的_ngcontent-hqi是什么含义
110 0
Angular应用里input字段后面的_ngcontent-hqi是什么含义
Angular如何自定义attribute指令
Angular如何自定义attribute指令
116 0
Angular如何自定义attribute指令