@@ -19,7 +19,7 @@ import {
|
||||
import {OnDestroy} from 'angular2/core';
|
||||
import {Injector} from 'angular2/core';
|
||||
import {NgIf} from 'angular2/common';
|
||||
import {Component, View, ViewMetadata} from 'angular2/src/core/metadata';
|
||||
import {Component, ViewMetadata} from 'angular2/src/core/metadata';
|
||||
import {DynamicComponentLoader} from 'angular2/src/core/linker/dynamic_component_loader';
|
||||
import {ElementRef, ElementRef_} from 'angular2/src/core/linker/element_ref';
|
||||
import {DOCUMENT} from 'angular2/src/platform/dom/dom_tokens';
|
||||
@@ -369,10 +369,7 @@ function createRootElement(doc: any, name: string): any {
|
||||
return rootEl;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'child-cmp',
|
||||
})
|
||||
@View({template: '{{ctxProp}}'})
|
||||
@Component({selector: 'child-cmp', template: '{{ctxProp}}'})
|
||||
class ChildComp {
|
||||
ctxProp: string;
|
||||
constructor() { this.ctxProp = 'hello'; }
|
||||
@@ -381,8 +378,11 @@ class ChildComp {
|
||||
|
||||
class DynamicallyCreatedComponentService {}
|
||||
|
||||
@Component({selector: 'hello-cmp', viewProviders: [DynamicallyCreatedComponentService]})
|
||||
@View({template: "{{greeting}}"})
|
||||
@Component({
|
||||
selector: 'hello-cmp',
|
||||
viewProviders: [DynamicallyCreatedComponentService],
|
||||
template: "{{greeting}}"
|
||||
})
|
||||
class DynamicallyCreatedCmp implements OnDestroy {
|
||||
greeting: string;
|
||||
dynamicallyCreatedComponentService: DynamicallyCreatedComponentService;
|
||||
@@ -396,48 +396,41 @@ class DynamicallyCreatedCmp implements OnDestroy {
|
||||
ngOnDestroy() { this.destroyed = true; }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: "DynamicallyLoaded;"})
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded;"})
|
||||
class DynamicallyLoaded {
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: "DynamicallyLoaded;"})
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded;"})
|
||||
class DynamicallyLoadedThrows {
|
||||
constructor() { throw new BaseException("ThrownInConstructor"); }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: "DynamicallyLoaded2;"})
|
||||
@Component({selector: 'dummy', template: "DynamicallyLoaded2;"})
|
||||
class DynamicallyLoaded2 {
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy', host: {'[id]': 'id'}})
|
||||
@View({template: "DynamicallyLoadedWithHostProps;"})
|
||||
@Component({selector: 'dummy', host: {'[id]': 'id'}, template: "DynamicallyLoadedWithHostProps;"})
|
||||
class DynamicallyLoadedWithHostProps {
|
||||
id: string;
|
||||
|
||||
constructor() { this.id = "default"; }
|
||||
}
|
||||
|
||||
@Component({selector: 'dummy'})
|
||||
@View({template: "dynamic(<ng-content></ng-content>)"})
|
||||
@Component({selector: 'dummy', template: "dynamic(<ng-content></ng-content>)"})
|
||||
class DynamicallyLoadedWithNgContent {
|
||||
id: string;
|
||||
|
||||
constructor() { this.id = "default"; }
|
||||
}
|
||||
|
||||
@Component({selector: 'location'})
|
||||
@View({template: "Location;"})
|
||||
@Component({selector: 'location', template: "Location;"})
|
||||
class Location {
|
||||
elementRef: ElementRef;
|
||||
|
||||
constructor(elementRef: ElementRef) { this.elementRef = elementRef; }
|
||||
}
|
||||
|
||||
@Component({selector: 'my-comp'})
|
||||
@View({directives: []})
|
||||
@Component({selector: 'my-comp', directives: []})
|
||||
class MyComp {
|
||||
ctxBoolProp: boolean;
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ import {
|
||||
import {
|
||||
Directive,
|
||||
Component,
|
||||
View,
|
||||
ViewMetadata,
|
||||
Attribute,
|
||||
Query,
|
||||
@@ -1358,8 +1357,7 @@ function declareTests() {
|
||||
try {
|
||||
tcb.createAsync(ComponentWithoutView);
|
||||
} catch (e) {
|
||||
expect(e.message)
|
||||
.toContain(`must have either 'template', 'templateUrl', or '@View' set.`);
|
||||
expect(e.message).toContain(`must have either 'template' or 'templateUrl' set.`);
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
@@ -1936,8 +1934,7 @@ class MyService {
|
||||
constructor() { this.greeting = 'hello'; }
|
||||
}
|
||||
|
||||
@Component({selector: 'simple-imp-cmp'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'simple-imp-cmp', template: ''})
|
||||
@Injectable()
|
||||
class SimpleImperativeViewComponent {
|
||||
done;
|
||||
@@ -1979,9 +1976,12 @@ class DirectiveWithTitleAndHostProperty {
|
||||
title: string;
|
||||
}
|
||||
|
||||
@Component(
|
||||
{selector: 'push-cmp', inputs: ['prop'], changeDetection: ChangeDetectionStrategy.OnPush})
|
||||
@View({template: '{{field}}'})
|
||||
@Component({
|
||||
selector: 'push-cmp',
|
||||
inputs: ['prop'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: '{{field}}'
|
||||
})
|
||||
@Injectable()
|
||||
class PushCmp {
|
||||
numberOfChecks: number;
|
||||
@@ -1998,9 +1998,9 @@ class PushCmp {
|
||||
@Component({
|
||||
selector: 'push-cmp-with-ref',
|
||||
inputs: ['prop'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: '{{field}}'
|
||||
})
|
||||
@View({template: '{{field}}'})
|
||||
@Injectable()
|
||||
class PushCmpWithRef {
|
||||
numberOfChecks: number;
|
||||
@@ -2055,8 +2055,7 @@ class PushCmpWithAsyncPipe {
|
||||
resolve(value) { this.completer.resolve(value); }
|
||||
}
|
||||
|
||||
@Component({selector: 'my-comp'})
|
||||
@View({directives: []})
|
||||
@Component({selector: 'my-comp', directives: []})
|
||||
@Injectable()
|
||||
class MyComp {
|
||||
ctxProp: string;
|
||||
@@ -2071,8 +2070,13 @@ class MyComp {
|
||||
throwError() { throw 'boom'; }
|
||||
}
|
||||
|
||||
@Component({selector: 'child-cmp', inputs: ['dirProp'], viewProviders: [MyService]})
|
||||
@View({directives: [MyDir], template: '{{ctxProp}}'})
|
||||
@Component({
|
||||
selector: 'child-cmp',
|
||||
inputs: ['dirProp'],
|
||||
viewProviders: [MyService],
|
||||
directives: [MyDir],
|
||||
template: '{{ctxProp}}'
|
||||
})
|
||||
@Injectable()
|
||||
class ChildComp {
|
||||
ctxProp: string;
|
||||
@@ -2083,15 +2087,13 @@ class ChildComp {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'child-cmp-no-template'})
|
||||
@View({directives: [], template: ''})
|
||||
@Component({selector: 'child-cmp-no-template', directives: [], template: ''})
|
||||
@Injectable()
|
||||
class ChildCompNoTemplate {
|
||||
ctxProp: string = 'hello';
|
||||
}
|
||||
|
||||
@Component({selector: 'child-cmp-svc'})
|
||||
@View({template: '{{ctxProp}}'})
|
||||
@Component({selector: 'child-cmp-svc', template: '{{ctxProp}}'})
|
||||
@Injectable()
|
||||
class ChildCompUsingService {
|
||||
ctxProp: string;
|
||||
@@ -2105,8 +2107,11 @@ class SomeDirective {
|
||||
|
||||
class SomeDirectiveMissingAnnotation {}
|
||||
|
||||
@Component({selector: 'cmp-with-host'})
|
||||
@View({template: '<p>Component with an injected host</p>', directives: [SomeDirective]})
|
||||
@Component({
|
||||
selector: 'cmp-with-host',
|
||||
template: '<p>Component with an injected host</p>',
|
||||
directives: [SomeDirective]
|
||||
})
|
||||
@Injectable()
|
||||
class CompWithHost {
|
||||
myHost: SomeDirective;
|
||||
@@ -2283,8 +2288,8 @@ class ToolbarViewContainer {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'toolbar'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'toolbar',
|
||||
template: 'TOOLBAR(<div *ngFor="var part of query" [toolbarVc]="part"></div>)',
|
||||
directives: [ToolbarViewContainer, NgFor]
|
||||
})
|
||||
@@ -2321,9 +2326,9 @@ function createInjectableWithLogging(inj: Injector) {
|
||||
selector: 'component-providing-logging-injectable',
|
||||
providers: [
|
||||
new Provider(InjectableService, {useFactory: createInjectableWithLogging, deps: [Injector]})
|
||||
]
|
||||
],
|
||||
template: ''
|
||||
})
|
||||
@View({template: ''})
|
||||
@Injectable()
|
||||
class ComponentProvidingLoggingInjectable {
|
||||
created: boolean = false;
|
||||
@@ -2335,8 +2340,11 @@ class ComponentProvidingLoggingInjectable {
|
||||
class DirectiveProvidingInjectable {
|
||||
}
|
||||
|
||||
@Component({selector: 'directive-providing-injectable', viewProviders: [[InjectableService]]})
|
||||
@View({template: ''})
|
||||
@Component({
|
||||
selector: 'directive-providing-injectable',
|
||||
viewProviders: [[InjectableService]],
|
||||
template: ''
|
||||
})
|
||||
@Injectable()
|
||||
class DirectiveProvidingInjectableInView {
|
||||
}
|
||||
@@ -2344,16 +2352,15 @@ class DirectiveProvidingInjectableInView {
|
||||
@Component({
|
||||
selector: 'directive-providing-injectable',
|
||||
providers: [new Provider(InjectableService, {useValue: 'host'})],
|
||||
viewProviders: [new Provider(InjectableService, {useValue: 'view'})]
|
||||
viewProviders: [new Provider(InjectableService, {useValue: 'view'})],
|
||||
template: ''
|
||||
})
|
||||
@View({template: ''})
|
||||
@Injectable()
|
||||
class DirectiveProvidingInjectableInHostAndView {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'directive-consuming-injectable'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'directive-consuming-injectable', template: ''})
|
||||
@Injectable()
|
||||
class DirectiveConsumingInjectable {
|
||||
injectable;
|
||||
@@ -2369,8 +2376,7 @@ class DirectiveContainingDirectiveConsumingAnInjectable {
|
||||
directive;
|
||||
}
|
||||
|
||||
@Component({selector: 'directive-consuming-injectable-unbounded'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'directive-consuming-injectable-unbounded', template: ''})
|
||||
@Injectable()
|
||||
class DirectiveConsumingInjectableUnbounded {
|
||||
injectable;
|
||||
@@ -2413,9 +2419,7 @@ function createParentBus(peb) {
|
||||
providers: [
|
||||
new Provider(EventBus,
|
||||
{useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]})
|
||||
]
|
||||
})
|
||||
@View({
|
||||
],
|
||||
directives: [forwardRef(() => ChildConsumingEventBus)],
|
||||
template: `
|
||||
<child-consuming-event-bus></child-consuming-event-bus>
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
Directive,
|
||||
ElementRef,
|
||||
TemplateRef,
|
||||
View,
|
||||
ViewContainerRef,
|
||||
ViewEncapsulation,
|
||||
ViewMetadata
|
||||
@@ -580,26 +579,28 @@ export function main() {
|
||||
});
|
||||
}
|
||||
|
||||
@Component({selector: 'main'})
|
||||
@View({template: '', directives: []})
|
||||
@Component({selector: 'main', template: '', directives: []})
|
||||
class MainComp {
|
||||
text: string = '';
|
||||
}
|
||||
|
||||
@Component({selector: 'other'})
|
||||
@View({template: '', directives: []})
|
||||
@Component({selector: 'other', template: '', directives: []})
|
||||
class OtherComp {
|
||||
text: string = '';
|
||||
}
|
||||
|
||||
@Component({selector: 'simple', inputs: ['stringProp']})
|
||||
@View({template: 'SIMPLE(<ng-content></ng-content>)', directives: []})
|
||||
@Component({
|
||||
selector: 'simple',
|
||||
inputs: ['stringProp'],
|
||||
template: 'SIMPLE(<ng-content></ng-content>)',
|
||||
directives: []
|
||||
})
|
||||
class Simple {
|
||||
stringProp: string = '';
|
||||
}
|
||||
|
||||
@Component({selector: 'simple-native1'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'simple-native1',
|
||||
template: 'SIMPLE1(<content></content>)',
|
||||
directives: [],
|
||||
encapsulation: ViewEncapsulation.Native,
|
||||
@@ -608,8 +609,8 @@ class Simple {
|
||||
class SimpleNative1 {
|
||||
}
|
||||
|
||||
@Component({selector: 'simple-native2'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'simple-native2',
|
||||
template: 'SIMPLE2(<content></content>)',
|
||||
directives: [],
|
||||
encapsulation: ViewEncapsulation.Native,
|
||||
@@ -618,13 +619,12 @@ class SimpleNative1 {
|
||||
class SimpleNative2 {
|
||||
}
|
||||
|
||||
@Component({selector: 'empty'})
|
||||
@View({template: '', directives: []})
|
||||
@Component({selector: 'empty', template: '', directives: []})
|
||||
class Empty {
|
||||
}
|
||||
|
||||
@Component({selector: 'multiple-content-tags'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'multiple-content-tags',
|
||||
template: '(<ng-content SELECT=".left"></ng-content>, <ng-content></ng-content>)',
|
||||
directives: []
|
||||
})
|
||||
@@ -645,16 +645,16 @@ class ProjectDirective {
|
||||
hide() { this.vc.clear(); }
|
||||
}
|
||||
|
||||
@Component({selector: 'outer-with-indirect-nested'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'outer-with-indirect-nested',
|
||||
template: 'OUTER(<simple><div><ng-content></ng-content></div></simple>)',
|
||||
directives: [Simple]
|
||||
})
|
||||
class OuterWithIndirectNestedComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'outer'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'outer',
|
||||
template:
|
||||
'OUTER(<inner><ng-content select=".left" class="left"></ng-content><ng-content></ng-content></inner>)',
|
||||
directives: [forwardRef(() => InnerComponent)]
|
||||
@@ -662,8 +662,8 @@ class OuterWithIndirectNestedComponent {
|
||||
class OuterComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'inner'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'inner',
|
||||
template:
|
||||
'INNER(<innerinner><ng-content select=".left" class="left"></ng-content><ng-content></ng-content></innerinner>)',
|
||||
directives: [forwardRef(() => InnerInnerComponent)]
|
||||
@@ -671,16 +671,16 @@ class OuterComponent {
|
||||
class InnerComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'innerinner'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'innerinner',
|
||||
template: 'INNERINNER(<ng-content select=".left"></ng-content>,<ng-content></ng-content>)',
|
||||
directives: []
|
||||
})
|
||||
class InnerInnerComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'conditional-content'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'conditional-content',
|
||||
template:
|
||||
'<div>(<div *manual><ng-content select=".left"></ng-content></div>, <ng-content></ng-content>)</div>',
|
||||
directives: [ManualViewportDirective]
|
||||
@@ -688,8 +688,8 @@ class InnerInnerComponent {
|
||||
class ConditionalContentComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'conditional-text'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'conditional-text',
|
||||
template:
|
||||
'MAIN(<template manual>FIRST(<template manual>SECOND(<ng-content></ng-content>)</template>)</template>)',
|
||||
directives: [ManualViewportDirective]
|
||||
@@ -697,16 +697,17 @@ class ConditionalContentComponent {
|
||||
class ConditionalTextComponent {
|
||||
}
|
||||
|
||||
@Component({selector: 'tab'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'tab',
|
||||
template: '<div><div *manual>TAB(<ng-content></ng-content>)</div></div>',
|
||||
directives: [ManualViewportDirective]
|
||||
})
|
||||
class Tab {
|
||||
}
|
||||
|
||||
@Component({selector: 'tree', inputs: ['depth']})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'tree',
|
||||
inputs: ['depth'],
|
||||
template: 'TREE({{depth}}:<tree *manual [depth]="depth+1"></tree>)',
|
||||
directives: [ManualViewportDirective, Tree]
|
||||
})
|
||||
@@ -715,8 +716,7 @@ class Tree {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'cmp-d'})
|
||||
@View({template: `<d>{{tagName}}</d>`})
|
||||
@Component({selector: 'cmp-d', template: `<d>{{tagName}}</d>`})
|
||||
class CmpD {
|
||||
tagName: string;
|
||||
constructor(elementRef: ElementRef) {
|
||||
@@ -725,8 +725,7 @@ class CmpD {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'cmp-c'})
|
||||
@View({template: `<c>{{tagName}}</c>`})
|
||||
@Component({selector: 'cmp-c', template: `<c>{{tagName}}</c>`})
|
||||
class CmpC {
|
||||
tagName: string;
|
||||
constructor(elementRef: ElementRef) {
|
||||
@@ -735,43 +734,37 @@ class CmpC {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'cmp-b'})
|
||||
@View({template: `<ng-content></ng-content><cmp-d></cmp-d>`, directives: [CmpD]})
|
||||
@Component({selector: 'cmp-b', template: `<ng-content></ng-content><cmp-d></cmp-d>`, directives: [CmpD]})
|
||||
class CmpB {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'cmp-a'})
|
||||
@View({template: `<ng-content></ng-content><cmp-c></cmp-c>`, directives: [CmpC]})
|
||||
@Component({selector: 'cmp-a', template: `<ng-content></ng-content><cmp-c></cmp-c>`, directives: [CmpC]})
|
||||
class CmpA {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-b11'})
|
||||
@View({template: `{{'b11'}}`, directives: []})
|
||||
@Component({selector: 'cmp-b11', template: `{{'b11'}}`, directives: []})
|
||||
class CmpB11 {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-b12'})
|
||||
@View({template: `{{'b12'}}`, directives: []})
|
||||
@Component({selector: 'cmp-b12', template: `{{'b12'}}`, directives: []})
|
||||
class CmpB12 {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-b21'})
|
||||
@View({template: `{{'b21'}}`, directives: []})
|
||||
@Component({selector: 'cmp-b21', template: `{{'b21'}}`, directives: []})
|
||||
class CmpB21 {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-b22'})
|
||||
@View({template: `{{'b22'}}`, directives: []})
|
||||
@Component({selector: 'cmp-b22', template: `{{'b22'}}`, directives: []})
|
||||
class CmpB22 {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-a1'})
|
||||
@View({template: `{{'a1'}}<cmp-b11></cmp-b11><cmp-b12></cmp-b12>`, directives: [CmpB11, CmpB12]})
|
||||
@Component(
|
||||
{selector: 'cmp-a1', template: `{{'a1'}}<cmp-b11></cmp-b11><cmp-b12></cmp-b12>`, directives: [CmpB11, CmpB12]})
|
||||
class CmpA1 {
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp-a2'})
|
||||
@View({template: `{{'a2'}}<cmp-b21></cmp-b21><cmp-b22></cmp-b22>`, directives: [CmpB21, CmpB22]})
|
||||
@Component(
|
||||
{selector: 'cmp-a2', template: `{{'a2'}}<cmp-b21></cmp-b21><cmp-b22></cmp-b22>`, directives: [CmpB21, CmpB22]})
|
||||
class CmpA2 {
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
TemplateRef,
|
||||
Query,
|
||||
QueryList,
|
||||
View,
|
||||
ViewQuery,
|
||||
ContentChildren,
|
||||
ViewChildren,
|
||||
@@ -693,8 +692,7 @@ class TextDirective {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-content-children'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'needs-content-children', template: ''})
|
||||
class NeedsContentChildren implements AfterContentInit {
|
||||
@ContentChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
||||
numberOfChildrenAfterContentInit: number;
|
||||
@@ -702,8 +700,8 @@ class NeedsContentChildren implements AfterContentInit {
|
||||
ngAfterContentInit() { this.numberOfChildrenAfterContentInit = this.textDirChildren.length; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-children'})
|
||||
@View({template: '<div text></div>', directives: [TextDirective]})
|
||||
@Component(
|
||||
{selector: 'needs-view-children', template: '<div text></div>', directives: [TextDirective]})
|
||||
class NeedsViewChildren implements AfterViewInit {
|
||||
@ViewChildren(TextDirective) textDirChildren: QueryList<TextDirective>;
|
||||
numberOfChildrenAfterViewInit: number;
|
||||
@@ -711,8 +709,7 @@ class NeedsViewChildren implements AfterViewInit {
|
||||
ngAfterViewInit() { this.numberOfChildrenAfterViewInit = this.textDirChildren.length; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-content-child'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'needs-content-child', template: ''})
|
||||
class NeedsContentChild implements AfterContentInit, AfterContentChecked {
|
||||
_child: TextDirective;
|
||||
|
||||
@@ -732,8 +729,8 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-child'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-view-child',
|
||||
template: `
|
||||
<div *ngIf="shouldShow" text="foo"></div>
|
||||
`,
|
||||
@@ -764,8 +761,8 @@ class InertDirective {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-query'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-query',
|
||||
directives: [NgFor, TextDirective],
|
||||
template: '<div text="ignoreme"></div><b *ngFor="var dir of query">{{dir.text}}|</b>'
|
||||
})
|
||||
@@ -775,8 +772,7 @@ class NeedsQuery {
|
||||
constructor(@Query(TextDirective) query: QueryList<TextDirective>) { this.query = query; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-four-queries'})
|
||||
@View({template: ''})
|
||||
@Component({selector: 'needs-four-queries', template: ''})
|
||||
class NeedsFourQueries {
|
||||
@ContentChild(TextDirective) query1: TextDirective;
|
||||
@ContentChild(TextDirective) query2: TextDirective;
|
||||
@@ -784,8 +780,11 @@ class NeedsFourQueries {
|
||||
@ContentChild(TextDirective) query4: TextDirective;
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-query-desc'})
|
||||
@View({directives: [NgFor], template: '<div *ngFor="var dir of query">{{dir.text}}|</div>'})
|
||||
@Component({
|
||||
selector: 'needs-query-desc',
|
||||
directives: [NgFor],
|
||||
template: '<div *ngFor="var dir of query">{{dir.text}}|</div>'
|
||||
})
|
||||
@Injectable()
|
||||
class NeedsQueryDesc {
|
||||
query: QueryList<TextDirective>;
|
||||
@@ -794,8 +793,7 @@ class NeedsQueryDesc {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-query-by-var-binding'})
|
||||
@View({directives: [], template: '<ng-content>'})
|
||||
@Component({selector: 'needs-query-by-var-binding', directives: [], template: '<ng-content>'})
|
||||
@Injectable()
|
||||
class NeedsQueryByLabel {
|
||||
query: QueryList<any>;
|
||||
@@ -804,16 +802,18 @@ class NeedsQueryByLabel {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-query-by-var-binding'})
|
||||
@View({directives: [], template: '<div #textLabel>text</div>'})
|
||||
@Component({
|
||||
selector: 'needs-view-query-by-var-binding',
|
||||
directives: [],
|
||||
template: '<div #textLabel>text</div>'
|
||||
})
|
||||
@Injectable()
|
||||
class NeedsViewQueryByLabel {
|
||||
query: QueryList<any>;
|
||||
constructor(@ViewQuery("textLabel") query: QueryList<any>) { this.query = query; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-query-by-var-bindings'})
|
||||
@View({directives: [], template: '<ng-content>'})
|
||||
@Component({selector: 'needs-query-by-var-bindings', directives: [], template: '<ng-content>'})
|
||||
@Injectable()
|
||||
class NeedsQueryByTwoLabels {
|
||||
query: QueryList<any>;
|
||||
@@ -822,8 +822,8 @@ class NeedsQueryByTwoLabels {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-query-and-project'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-query-and-project',
|
||||
directives: [NgFor],
|
||||
template: '<div *ngFor="var dir of query">{{dir.text}}|</div><ng-content></ng-content>'
|
||||
})
|
||||
@@ -833,8 +833,8 @@ class NeedsQueryAndProject {
|
||||
constructor(@Query(TextDirective) query: QueryList<TextDirective>) { this.query = query; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-query'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-view-query',
|
||||
directives: [TextDirective],
|
||||
template: '<div text="1"><div text="2"></div></div>' +
|
||||
'<div text="3"></div><div text="4"></div>'
|
||||
@@ -845,8 +845,11 @@ class NeedsViewQuery {
|
||||
constructor(@ViewQuery(TextDirective) query: QueryList<TextDirective>) { this.query = query; }
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-query-if'})
|
||||
@View({directives: [NgIf, TextDirective], template: '<div *ngIf="show" text="1"></div>'})
|
||||
@Component({
|
||||
selector: 'needs-view-query-if',
|
||||
directives: [NgIf, TextDirective],
|
||||
template: '<div *ngIf="show" text="1"></div>'
|
||||
})
|
||||
@Injectable()
|
||||
class NeedsViewQueryIf {
|
||||
show: boolean;
|
||||
@@ -858,8 +861,8 @@ class NeedsViewQueryIf {
|
||||
}
|
||||
|
||||
|
||||
@Component({selector: 'needs-view-query-nested-if'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-view-query-nested-if',
|
||||
directives: [NgIf, InertDirective, TextDirective],
|
||||
template: '<div text="1"><div *ngIf="show"><div dir></div></div></div>'
|
||||
})
|
||||
@@ -873,8 +876,8 @@ class NeedsViewQueryNestedIf {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-query-order'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-view-query-order',
|
||||
directives: [NgFor, TextDirective, InertDirective],
|
||||
template: '<div text="1"></div>' +
|
||||
'<div *ngFor="var i of list" [text]="i"></div>' +
|
||||
@@ -890,8 +893,8 @@ class NeedsViewQueryOrder {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-view-query-order-with-p'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'needs-view-query-order-with-p',
|
||||
directives: [NgFor, TextDirective, InertDirective],
|
||||
template: '<div dir><div text="1"></div>' +
|
||||
'<div *ngFor="var i of list" [text]="i"></div>' +
|
||||
@@ -907,8 +910,7 @@ class NeedsViewQueryOrderWithParent {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'needs-tpl'})
|
||||
@View({template: '<template var-x="shadow"></template>'})
|
||||
@Component({selector: 'needs-tpl', template: '<template var-x="shadow"></template>'})
|
||||
class NeedsTpl {
|
||||
viewQuery: QueryList<TemplateRef>;
|
||||
query: QueryList<TemplateRef>;
|
||||
@@ -919,8 +921,8 @@ class NeedsTpl {
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'my-comp'})
|
||||
@View({
|
||||
@Component({
|
||||
selector: 'my-comp',
|
||||
directives: [
|
||||
NeedsQuery,
|
||||
NeedsQueryDesc,
|
||||
@@ -943,7 +945,8 @@ class NeedsTpl {
|
||||
NgIf,
|
||||
NgFor,
|
||||
NeedsFourQueries
|
||||
]
|
||||
],
|
||||
template: ''
|
||||
})
|
||||
@Injectable()
|
||||
class MyComp {
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/testing_internal';
|
||||
import {ViewResolver} from 'angular2/src/core/linker/view_resolver';
|
||||
import {Component, View, ViewMetadata} from 'angular2/src/core/metadata';
|
||||
import {Component, ViewMetadata} from 'angular2/src/core/metadata';
|
||||
|
||||
class SomeDir {}
|
||||
class SomePipe {}
|
||||
|
||||
@Component({selector: 'sample'})
|
||||
@View(
|
||||
{template: "some template", directives: [SomeDir], pipes: [SomePipe], styles: ["some styles"]})
|
||||
@Component({
|
||||
selector: 'sample',
|
||||
template: "some template",
|
||||
directives: [SomeDir],
|
||||
pipes: [SomePipe],
|
||||
styles: ["some styles"]
|
||||
})
|
||||
class ComponentWithView {
|
||||
}
|
||||
|
||||
@@ -22,12 +26,10 @@ class ComponentWithTemplate {
|
||||
}
|
||||
|
||||
@Component({selector: 'sample', template: "some template"})
|
||||
@View({template: "some template"})
|
||||
class ComponentWithViewTemplate {
|
||||
}
|
||||
|
||||
@Component({selector: 'sample', templateUrl: "some template url"})
|
||||
@View({template: "some template"})
|
||||
@Component({selector: 'sample', templateUrl: "some template url", template: "some template"})
|
||||
class ComponentWithViewTemplateUrl {
|
||||
}
|
||||
|
||||
@@ -35,9 +37,6 @@ class ComponentWithViewTemplateUrl {
|
||||
class ComponentWithoutView {
|
||||
}
|
||||
|
||||
@View({template: "some template"})
|
||||
class ClassWithView {
|
||||
}
|
||||
|
||||
class SimpleClass {}
|
||||
|
||||
@@ -47,17 +46,6 @@ export function main() {
|
||||
|
||||
beforeEach(() => { resolver = new ViewResolver(); });
|
||||
|
||||
it('should read out the View metadata', () => {
|
||||
var viewMetadata = resolver.resolve(ComponentWithView);
|
||||
expect(viewMetadata)
|
||||
.toEqual(new View({
|
||||
template: "some template",
|
||||
directives: [SomeDir],
|
||||
pipes: [SomePipe],
|
||||
styles: ["some styles"]
|
||||
}));
|
||||
});
|
||||
|
||||
it('should read out the View metadata from the Component metadata', () => {
|
||||
var viewMetadata = resolver.resolve(ComponentWithTemplate);
|
||||
expect(viewMetadata)
|
||||
@@ -69,32 +57,15 @@ export function main() {
|
||||
}));
|
||||
});
|
||||
|
||||
it('should read out the View metadata from a simple class', () => {
|
||||
var viewMetadata = resolver.resolve(ClassWithView);
|
||||
expect(viewMetadata).toEqual(new View({template: "some template"}));
|
||||
});
|
||||
|
||||
it('should throw when Component.template is specified together with the View metadata', () => {
|
||||
expect(() => resolver.resolve(ComponentWithViewTemplate))
|
||||
.toThrowErrorWith(
|
||||
"Component 'ComponentWithViewTemplate' cannot have both 'template' and '@View' set at the same time");
|
||||
});
|
||||
|
||||
it('should throw when Component.template is specified together with the View metadata', () => {
|
||||
expect(() => resolver.resolve(ComponentWithViewTemplateUrl))
|
||||
.toThrowErrorWith(
|
||||
"Component 'ComponentWithViewTemplateUrl' cannot have both 'templateUrl' and '@View' set at the same time");
|
||||
});
|
||||
|
||||
it('should throw when Component has no View decorator and no template is set', () => {
|
||||
expect(() => resolver.resolve(ComponentWithoutView))
|
||||
.toThrowErrorWith(
|
||||
"Component 'ComponentWithoutView' must have either 'template', 'templateUrl', or '@View' set");
|
||||
"Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set");
|
||||
});
|
||||
|
||||
it('should throw when simple class has no View decorator and no template is set', () => {
|
||||
expect(() => resolver.resolve(SimpleClass))
|
||||
.toThrowErrorWith("No View decorator found on component 'SimpleClass'");
|
||||
.toThrowErrorWith("Could not compile 'SimpleClass' because it is not a component.");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user