Angular HTML template的解析位置

时间:2022-07-23
本文章向大家介绍Angular HTML template的解析位置,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

文件:

compiler.umd.js

path:

turbo_modules/@angular/compiler@9.1.12/bundles:

函数名:TemplateParser.prototype.parse

TemplateParser.prototype.parse = function(component, template, directives, pipes, schemas, templateUrl, preserveWhitespaces) {
                    var result = this.tryParse(component, template, directives, pipes, schemas, templateUrl, preserveWhitespaces);
                    var warnings = result.errors.filter(function(error) {
                        return error.level === exports.ParseErrorLevel.WARNING;
                    });
                    var errors = result.errors.filter(function(error) {
                        return error.level === exports.ParseErrorLevel.ERROR;
                    });
                    if (warnings.length > 0) {
                        this._console.warn("Template parse warnings:n" + warnings.join('n'));
                    }
                    if (errors.length > 0) {
                        var errorString = errors.join('n');
                        throw syntaxError("Template parse errors:n" + errorString, errors);
                    }
                    return {
                        template: result.templateAst,
                        pipes: result.usedPipes
                    };
                }

如果把form后面中括号的formGroup改成formGroup2:

错误消息:Can’t bind to ‘formGroup2’ since it isn’t a known property of ‘form’. ("

检查逻辑位于compiler.umd.js里的TemplateParseVisitor.prototype._checkPropertiesInSchema函数:

检查的具体细节:Schema里包含的form元数据:

报错: