refactor(core): introduce NgModule.schemas
This allows Angular to error on unknown properties, allowing applications that don’t use custom elements to get better error reporting. Part of #10043 BREAKING CHANGE: - By default, Angular will error during parsing on unknown properties, even if they are on elements with a `-` in their name (aka custom elements). If you application is using custom elements, fill the new parameter `@NgModule.schemas` with the value `[CUSTOM_ELEMENTS_SCHEMA]`. E.g. for bootstrap: ``` bootstrap(MyComponent, {schemas: [CUSTOM_ELEMENTS_SCHEMA]}); ```
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injectable, SecurityContext} from '@angular/core';
|
||||
import {CUSTOM_ELEMENTS_SCHEMA, Injectable, SchemaMetadata, SecurityContext} from '@angular/core';
|
||||
|
||||
import {StringMapWrapper} from '../facade/collection';
|
||||
import {isPresent} from '../facade/lang';
|
||||
@ -270,7 +270,9 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
|
||||
});
|
||||
}
|
||||
|
||||
hasProperty(tagName: string, propName: string): boolean {
|
||||
hasProperty(tagName: string, propName: string, schemaMetas: SchemaMetadata[]): boolean {
|
||||
const hasCustomElementSchema =
|
||||
schemaMetas.some((schema) => schema.name === CUSTOM_ELEMENTS_SCHEMA.name);
|
||||
if (tagName.indexOf('-') !== -1) {
|
||||
if (tagName === 'ng-container' || tagName === 'ng-content') {
|
||||
return false;
|
||||
@ -278,7 +280,7 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
|
||||
|
||||
// Can't tell now as we don't know which properties a custom element will get
|
||||
// once it is instantiated
|
||||
return true;
|
||||
return hasCustomElementSchema;
|
||||
} else {
|
||||
var elementProperties = this.schema[tagName.toLowerCase()];
|
||||
if (!isPresent(elementProperties)) {
|
||||
|
@ -6,8 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {SchemaMetadata} from '@angular/core';
|
||||
|
||||
export abstract class ElementSchemaRegistry {
|
||||
abstract hasProperty(tagName: string, propName: string): boolean;
|
||||
abstract hasProperty(tagName: string, propName: string, schemaMetas: SchemaMetadata[]): boolean;
|
||||
abstract securityContext(tagName: string, propName: string): any;
|
||||
abstract getMappedPropName(propName: string): string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user