diff --git a/modules/angular2/src/compiler/runtime_metadata.ts b/modules/angular2/src/compiler/runtime_metadata.ts index 2f7951a553..1fceb0e859 100644 --- a/modules/angular2/src/compiler/runtime_metadata.ts +++ b/modules/angular2/src/compiler/runtime_metadata.ts @@ -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 = dirMeta; + moduleUrl = calcModuleUrl(directiveType, cmpMeta); var viewMeta = this._viewResolver.resolve(directiveType); templateMeta = new cpl.CompileTemplateMetadata({ encapsulation: viewMeta.encapsulation, @@ -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 : diff --git a/modules/angular2/src/core/linker/directive_resolver.ts b/modules/angular2/src/core/linker/directive_resolver.ts index 380cbc9f22..1d19c4e9fe 100644 --- a/modules/angular2/src/core/linker/directive_resolver.ts +++ b/modules/angular2/src/core/linker/directive_resolver.ts @@ -132,7 +132,6 @@ export class DirectiveResolver { outputs: mergedOutputs, host: mergedHost, exportAs: dm.exportAs, - moduleId: dm.moduleId, queries: mergedQueries, providers: dm.providers }); diff --git a/modules/angular2/src/core/metadata.dart b/modules/angular2/src/core/metadata.dart index e47ed69c34..ec9f12cfac 100644 --- a/modules/angular2/src/core/metadata.dart +++ b/modules/angular2/src/core/metadata.dart @@ -27,7 +27,6 @@ class Directive extends DirectiveMetadata { List bindings, List providers, String exportAs, - String moduleId, Map queries}) : super( selector: selector, @@ -39,7 +38,6 @@ class Directive extends DirectiveMetadata { bindings: bindings, providers: providers, exportAs: exportAs, - moduleId: moduleId, queries: queries); } diff --git a/modules/angular2/src/core/metadata.ts b/modules/angular2/src/core/metadata.ts index a6f758837c..df3292be0f 100644 --- a/modules/angular2/src/core/metadata.ts +++ b/modules/angular2/src/core/metadata.ts @@ -146,7 +146,6 @@ export interface DirectiveFactory { bindings?: any[], providers?: any[], exportAs?: string, - moduleId?: string, queries?: {[key: string]: any} }): DirectiveDecorator; new (obj: { @@ -159,7 +158,6 @@ export interface DirectiveFactory { bindings?: any[], providers?: any[], exportAs?: string, - moduleId?: string, queries?: {[key: string]: any} }): DirectiveMetadata; } diff --git a/modules/angular2/src/core/metadata/directives.ts b/modules/angular2/src/core/metadata/directives.ts index 4c0c3ec611..b936e95509 100644 --- a/modules/angular2/src/core/metadata/directives.ts +++ b/modules/angular2/src/core/metadata/directives.ts @@ -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. @@ -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[], @@ -762,7 +742,6 @@ export class DirectiveMetadata extends InjectableMetadata { providers?: any[], /** @deprecated */ bindings?: any[], exportAs?: string, - moduleId?: string, queries?: {[key: string]: any} } = {}) { super(); @@ -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; @@ -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 { + * } + * + * ``` + */ + moduleId: string; + templateUrl: string; template: string; @@ -913,7 +911,6 @@ export class ComponentMetadata extends DirectiveMetadata { events: events, host: host, exportAs: exportAs, - moduleId: moduleId, bindings: bindings, providers: providers, queries: queries @@ -929,6 +926,7 @@ export class ComponentMetadata extends DirectiveMetadata { this.directives = directives; this.pipes = pipes; this.encapsulation = encapsulation; + this.moduleId = moduleId; } } diff --git a/modules/angular2/src/mock/directive_resolver_mock.ts b/modules/angular2/src/mock/directive_resolver_mock.ts index 9b1e0993fe..b6a6451265 100644 --- a/modules/angular2/src/mock/directive_resolver_mock.ts +++ b/modules/angular2/src/mock/directive_resolver_mock.ts @@ -47,7 +47,6 @@ export class MockDirectiveResolver extends DirectiveResolver { host: dm.host, providers: providers, exportAs: dm.exportAs, - moduleId: dm.moduleId, queries: dm.queries }); } diff --git a/modules/angular2/test/compiler/runtime_metadata_spec.ts b/modules/angular2/test/compiler/runtime_metadata_spec.ts index 46fd18e409..50ca069ca2 100644 --- a/modules/angular2/test/compiler/runtime_metadata_spec.ts +++ b/modules/angular2/test/compiler/runtime_metadata_spec.ts @@ -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((value).endsWith(expectedEndValue)).toBe(true); + expect(value.endsWith(expectedEndValue)).toBe(true); })); }); @@ -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", () => { @@ -91,10 +91,7 @@ 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)]); })); }); }); @@ -102,14 +99,16 @@ export function main() { }); } - - @Directive({selector: 'a-directive'}) class ADirective { } @Directive({selector: 'someSelector'}) -class DirectiveWithoutModuleId { +class SomeDirective { +} + +@Component({selector: 'someComponent', template: ''}) +class ComponentWithoutModuleId { } @Component({ @@ -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, diff --git a/modules/angular2/test/compiler/template_compiler_spec.ts b/modules/angular2/test/compiler/template_compiler_spec.ts index b09c0bc9ff..cb5c0234eb 100644 --- a/modules/angular2/test/compiler/template_compiler_spec.ts +++ b/modules/angular2/test/compiler/template_compiler_spec.ts @@ -321,7 +321,7 @@ class CompWithEmbeddedTemplate { } -@Directive({selector: 'plain', moduleId: THIS_MODULE_ID}) +@Directive({selector: 'plain'}) @View({template: ''}) class NonComponent { } diff --git a/modules/angular2/test/public_api_spec.ts b/modules/angular2/test/public_api_spec.ts index 5d7c2d915b..71fe8210ba 100644 --- a/modules/angular2/test/public_api_spec.ts +++ b/modules/angular2/test/public_api_spec.ts @@ -923,7 +923,6 @@ var NG_CORE = [ 'Directive.events', 'Directive.exportAs', 'Directive.host', - 'Directive.moduleId', 'Directive.inputs', 'Directive.properties', 'Directive.queries', @@ -935,7 +934,6 @@ var NG_CORE = [ 'DirectiveMetadata.events', 'DirectiveMetadata.exportAs', 'DirectiveMetadata.host', - 'DirectiveMetadata.moduleId', 'DirectiveMetadata.inputs', 'DirectiveMetadata.properties', 'DirectiveMetadata.queries',