X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions modules/angular2/src/compiler/runtime_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ export class RuntimeMetadataResolver {
var meta = this._cache.get(directiveType);
if (isBlank(meta)) {
var dirMeta = this._directiveResolver.resolve(directiveType);
var moduleUrl = calcModuleUrl(directiveType, dirMeta);
var moduleUrl = null;
var templateMeta = null;
var changeDetectionStrategy = null;

if (dirMeta instanceof md.ComponentMetadata) {
var cmpMeta = <md.ComponentMetadata>dirMeta;
moduleUrl = calcModuleUrl(directiveType, cmpMeta);
var viewMeta = this._viewResolver.resolve(directiveType);
templateMeta = new cpl.CompileTemplateMetadata({
encapsulation: viewMeta.encapsulation,
Expand Down Expand Up @@ -107,8 +108,8 @@ function isValidDirective(value: Type): boolean {
return isPresent(value) && (value instanceof Type);
}

function calcModuleUrl(type: Type, dirMeta: md.DirectiveMetadata): string {
var moduleId = dirMeta.moduleId;
function calcModuleUrl(type: Type, cmpMetadata: md.ComponentMetadata): string {
var moduleId = cmpMetadata.moduleId;
if (isPresent(moduleId)) {
var scheme = getUrlScheme(moduleId);
return isPresent(scheme) && scheme.length > 0 ? moduleId :
Expand Down
1 change: 0 additions & 1 deletion modules/angular2/src/core/linker/directive_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export class DirectiveResolver {
outputs: mergedOutputs,
host: mergedHost,
exportAs: dm.exportAs,
moduleId: dm.moduleId,
queries: mergedQueries,
providers: dm.providers
});
Expand Down
2 changes: 0 additions & 2 deletions modules/angular2/src/core/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Directive extends DirectiveMetadata {
List bindings,
List providers,
String exportAs,
String moduleId,
Map<String, dynamic> queries})
: super(
selector: selector,
Expand All @@ -39,7 +38,6 @@ class Directive extends DirectiveMetadata {
bindings: bindings,
providers: providers,
exportAs: exportAs,
moduleId: moduleId,
queries: queries);
}

Expand Down
2 changes: 0 additions & 2 deletions modules/angular2/src/core/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export interface DirectiveFactory {
bindings?: any[],
providers?: any[],
exportAs?: string,
moduleId?: string,
queries?: {[key: string]: any}
}): DirectiveDecorator;
new (obj: {
Expand All @@ -159,7 +158,6 @@ export interface DirectiveFactory {
bindings?: any[],
providers?: any[],
exportAs?: string,
moduleId?: string,
queries?: {[key: string]: any}
}): DirectiveMetadata;
}
Expand Down
46 changes: 22 additions & 24 deletions modules/angular2/src/core/metadata/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,26 +696,6 @@ export class DirectiveMetadata extends InjectableMetadata {
*/
exportAs: string;

/**
* The module id of the module that contains the directive.
* Needed to be able to resolve relative urls for templates and styles.
* In Dart, this can be determined automatically and does not need to be set.
* In CommonJS, this can always be set to `module.id`.
*
* ## Simple Example
*
* ```
* @Directive({
* selector: 'someDir',
* moduleId: module.id
* })
* class SomeDir {
* }
*
* ```
*/
moduleId: string;

// TODO: add an example after ContentChildren and ViewChildren are in master
/**
* Configures the queries that will be injected into the directive.
Expand Down Expand Up @@ -752,7 +732,7 @@ export class DirectiveMetadata extends InjectableMetadata {
queries: {[key: string]: any};

constructor({selector, inputs, outputs, properties, events, host, bindings, providers, exportAs,
moduleId, queries}: {
queries}: {
selector?: string,
inputs?: string[],
outputs?: string[],
Expand All @@ -762,7 +742,6 @@ export class DirectiveMetadata extends InjectableMetadata {
providers?: any[],
/** @deprecated */ bindings?: any[],
exportAs?: string,
moduleId?: string,
queries?: {[key: string]: any}
} = {}) {
super();
Expand All @@ -773,7 +752,6 @@ export class DirectiveMetadata extends InjectableMetadata {
this._events = events;
this.host = host;
this.exportAs = exportAs;
this.moduleId = moduleId;
this.queries = queries;
this._providers = providers;
this._bindings = bindings;
Expand Down Expand Up @@ -865,6 +843,26 @@ export class ComponentMetadata extends DirectiveMetadata {
private _viewProviders: any[];
private _viewBindings: any[];

/**
* The module id of the module that contains the component.
* Needed to be able to resolve relative urls for templates and styles.
* In Dart, this can be determined automatically and does not need to be set.
* In CommonJS, this can always be set to `module.id`.
*
* ## Simple Example
*
* ```
* @Directive({
* selector: 'someDir',
* moduleId: module.id
* })
* class SomeDir {
* }
*
* ```
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't directive be component in this block-comment ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks for catching

moduleId: string;

templateUrl: string;

template: string;
Expand Down Expand Up @@ -913,7 +911,6 @@ export class ComponentMetadata extends DirectiveMetadata {
events: events,
host: host,
exportAs: exportAs,
moduleId: moduleId,
bindings: bindings,
providers: providers,
queries: queries
Expand All @@ -929,6 +926,7 @@ export class ComponentMetadata extends DirectiveMetadata {
this.directives = directives;
this.pipes = pipes;
this.encapsulation = encapsulation;
this.moduleId = moduleId;
}
}

Expand Down
1 change: 0 additions & 1 deletion modules/angular2/src/mock/directive_resolver_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class MockDirectiveResolver extends DirectiveResolver {
host: dm.host,
providers: providers,
exportAs: dm.exportAs,
moduleId: dm.moduleId,
queries: dm.queries
});
}
Expand Down
21 changes: 10 additions & 11 deletions modules/angular2/test/compiler/runtime_metadata_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export function main() {

it('should use the moduleUrl from the reflector if none is given',
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
var value: string = resolver.getMetadata(DirectiveWithoutModuleId).type.moduleUrl;
var value: string = resolver.getMetadata(ComponentWithoutModuleId).type.moduleUrl;
var expectedEndValue =
IS_DART ? 'base/dist/dart/angular2/test/compiler/runtime_metadata_spec.dart' : './';
expect((<any>value).endsWith(expectedEndValue)).toBe(true);
expect(value.endsWith(expectedEndValue)).toBe(true);
}));
});

Expand All @@ -82,7 +82,7 @@ export function main() {
it('should return the directive metadatas',
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
.toEqual([resolver.getMetadata(DirectiveWithoutModuleId)]);
.toEqual([resolver.getMetadata(SomeDirective)]);
}));

describe("platform directives", () => {
Expand All @@ -91,25 +91,24 @@ export function main() {
it('should include platform directives when available',
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
.toEqual([
resolver.getMetadata(ADirective),
resolver.getMetadata(DirectiveWithoutModuleId)
]);
.toEqual([resolver.getMetadata(ADirective), resolver.getMetadata(SomeDirective)]);
}));
});
});

});
}



@Directive({selector: 'a-directive'})
class ADirective {
}

@Directive({selector: 'someSelector'})
class DirectiveWithoutModuleId {
class SomeDirective {
}

@Component({selector: 'someComponent', template: ''})
class ComponentWithoutModuleId {
}

@Component({
Expand All @@ -131,7 +130,7 @@ class DirectiveWithoutModuleId {
encapsulation: ViewEncapsulation.Emulated,
styles: ['someStyle'],
styleUrls: ['someStyleUrl'],
directives: [DirectiveWithoutModuleId]
directives: [SomeDirective]
})
class ComponentWithEverything implements OnChanges,
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/compiler/template_compiler_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class CompWithEmbeddedTemplate {
}


@Directive({selector: 'plain', moduleId: THIS_MODULE_ID})
@Directive({selector: 'plain'})
@View({template: ''})
class NonComponent {
}
Expand Down
2 changes: 0 additions & 2 deletions modules/angular2/test/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,6 @@ var NG_CORE = [
'Directive.events',
'Directive.exportAs',
'Directive.host',
'Directive.moduleId',
'Directive.inputs',
'Directive.properties',
'Directive.queries',
Expand All @@ -935,7 +934,6 @@ var NG_CORE = [
'DirectiveMetadata.events',
'DirectiveMetadata.exportAs',
'DirectiveMetadata.host',
'DirectiveMetadata.moduleId',
'DirectiveMetadata.inputs',
'DirectiveMetadata.properties',
'DirectiveMetadata.queries',
Expand Down
X Tutup