feat(core): introduce template context

BREAKING CHANGE:
- Before, a `EmbeddedViewRef` used to have methods for 
  setting variables. Now, a user has to pass in a context
  object that represents all variables when an `EmbeddedViewRef`
  should be created.
- `ViewContainerRef.createEmbeddedViewRef` now takes
   a context object as 2nd argument.
- `EmbeddedViewRef.setLocal` and `getLocal` have been removed.
  Use `EmbeddedViewRef.context` to access the context.
- `DebugNode.locals` has been removed. Use the new methods `DebugElement.references`
  to get the references that are present on this element,
  or `DebugElement.context` to get the context of the `EmbeddedViewRef` or the component to which the element belongs.

Closes #8321
This commit is contained in:
Tobias Bosch
2016-04-28 14:00:31 -07:00
parent 96ae348648
commit cacdead96d
28 changed files with 277 additions and 246 deletions

View File

@ -112,15 +112,15 @@ const CORE = [
'DebugNode',
'DebugNode.componentInstance:any',
'DebugNode.constructor(nativeNode:any, parent:DebugNode, _debugInfo:RenderDebugInfo)',
'DebugNode.getLocal(name:string):any',
'DebugNode.inject(token:any):any',
'DebugNode.injector:Injector',
'DebugNode.listeners:EventListener[]',
'DebugNode.locals:{[key:string]:any}',
'DebugNode.nativeNode:any',
'DebugNode.parent:DebugElement',
'DebugNode.providerTokens:any[]',
'DebugNode.source:string',
'DebugNode.context:any',
'DebugNode.references:{[key:string]:any}',
'DebugElement',
'DebugElement.children:DebugElement[]',
'DebugElement.nativeElement:any',
@ -164,10 +164,9 @@ const CORE = [
'ElementRef',
'ElementRef.nativeElement:any',
'ElementRef.constructor(nativeElement:any)',
'EmbeddedViewRef',
'EmbeddedViewRef.hasLocal(variableName:string):boolean',
'EmbeddedViewRef<C>',
'EmbeddedViewRef.context:C',
'EmbeddedViewRef.rootNodes:any[]',
'EmbeddedViewRef.setLocal(variableName:string, value:any):void',
'EmbeddedViewRef.destroy():any',
'EventEmitter.constructor(isAsync:boolean)',
'EventEmitter.emit(value:T):any',
@ -415,9 +414,9 @@ const CORE = [
'SkipSelfMetadataFactory',
'SkipSelfMetadata',
'SkipSelfMetadata.toString():string',
'TemplateRef',
'TemplateRef<C>',
'TemplateRef.elementRef:ElementRef',
'TemplateRef.createEmbeddedView():EmbeddedViewRef',
'TemplateRef.createEmbeddedView(context:C):EmbeddedViewRef<C>',
'Testability',
'Testability.constructor(_ngZone:NgZone)',
'Testability.decreasePendingRequestCount():number',
@ -446,7 +445,7 @@ const CORE = [
'ViewChildrenMetadata.constructor(_selector:Type|string, {read=null}:{read?:any})',
'ViewContainerRef',
'ViewContainerRef.clear():void',
'ViewContainerRef.createEmbeddedView(templateRef:TemplateRef, index:number):EmbeddedViewRef',
'ViewContainerRef.createEmbeddedView(templateRef:TemplateRef<any>, context:any, index:number):EmbeddedViewRef<any>',
'ViewContainerRef.createComponent(componentFactory:ComponentFactory, index:number, injector:Injector, projectableNodes:any[][]):ComponentRef',
'ViewContainerRef.detach(index:number):ViewRef',
'ViewContainerRef.element:ElementRef',
@ -692,10 +691,10 @@ const COMMON = [
'NgControlStatus.ngClassUntouched:boolean',
'NgControlStatus.ngClassValid:boolean',
'NgFor',
'NgFor.constructor(_viewContainer:ViewContainerRef, _templateRef:TemplateRef, _iterableDiffers:IterableDiffers, _cdr:ChangeDetectorRef)',
'NgFor.constructor(_viewContainer:ViewContainerRef, _templateRef:TemplateRef<NgForRow>, _iterableDiffers:IterableDiffers, _cdr:ChangeDetectorRef)',
'NgFor.ngDoCheck():any',
'NgFor.ngForOf=(value:any)',
'NgFor.ngForTemplate=(value:TemplateRef)',
'NgFor.ngForTemplate=(value:TemplateRef<NgForRow>)',
'NgFor.ngForTrackBy=(value:TrackByFn)',
'NgForm',
'NgForm.addControl(dir:NgControl):void',
@ -743,11 +742,11 @@ const COMMON = [
'NgFormModel.removeControlGroup(dir:NgControlGroup):any',
'NgFormModel.updateModel(dir:NgControl, value:any):void',
'NgIf',
'NgIf.constructor(_viewContainer:ViewContainerRef, _templateRef:TemplateRef)',
'NgIf.constructor(_viewContainer:ViewContainerRef, _templateRef:TemplateRef<Object>)',
'NgIf.ngIf=(newCondition:any)',
'NgTemplateOutlet',
'NgTemplateOutlet.constructor(_viewContainerRef:ViewContainerRef)',
'NgTemplateOutlet.ngTemplateOutlet=(templateRef:TemplateRef)',
'NgTemplateOutlet.ngTemplateOutlet=(templateRef:TemplateRef<Object>)',
'NgLocalization',
'NgLocalization.getPluralCategory(value:any):string',
'NgModel',
@ -765,7 +764,7 @@ const COMMON = [
'NgPlural.cases:QueryList<NgPluralCase>',
'NgPlural.constructor(_localization:NgLocalization)',
'NgPlural.ngAfterContentInit():any',
'NgPluralCase.constructor(value:string, template:TemplateRef, viewContainer:ViewContainerRef)',
'NgPluralCase.constructor(value:string, template:TemplateRef<Object>, viewContainer:ViewContainerRef)',
'NgPlural.ngPlural=(value:number)',
'NgPluralCase',
'NgSelectOption',
@ -781,9 +780,9 @@ const COMMON = [
'NgSwitch',
'NgSwitch.ngSwitch=(value:any)',
'NgSwitchDefault',
'NgSwitchDefault.constructor(viewContainer:ViewContainerRef, templateRef:TemplateRef, sswitch:NgSwitch)',
'NgSwitchDefault.constructor(viewContainer:ViewContainerRef, templateRef:TemplateRef<Object>, sswitch:NgSwitch)',
'NgSwitchWhen',
'NgSwitchWhen.constructor(viewContainer:ViewContainerRef, templateRef:TemplateRef, ngSwitch:NgSwitch)',
'NgSwitchWhen.constructor(viewContainer:ViewContainerRef, templateRef:TemplateRef<Object>, ngSwitch:NgSwitch)',
'NgSwitchWhen.ngSwitchWhen=(value:any)',
'NumberPipe',
'PatternValidator',