Skip to content

Commit 5039640

Browse files
committed
fix(@angular/cli): fix component not finding closest module
fixes angular#5127
1 parent 86d60bb commit 5039640

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/@angular/cli/blueprints/component/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export default Blueprint.extend({
9595
}
9696
} else {
9797
try {
98-
this.pathToModule = findParentModule(
99-
this.project.root, appConfig.root, this.dynamicPath.dir);
98+
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
10099
} catch (e) {
101100
if (!options.skipImport) {
102101
throw `Error locating module for declaration\n\t${e}`;
@@ -114,7 +113,7 @@ export default Blueprint.extend({
114113
const defaultPrefix = (appConfig && appConfig.prefix) || '';
115114

116115
let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
117-
? '' : (this.options.prefix || defaultPrefix);
116+
? '' : (this.options.prefix || defaultPrefix);
118117
prefix = prefix && `${prefix}-`;
119118

120119
this.selector = stringUtils.dasherize(prefix + parsedPath.name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { join } from 'path';
2+
import { ng } from '../../../utils/process';
3+
import { expectFileToMatch } from '../../../utils/fs';
4+
5+
6+
export default function () {
7+
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');
8+
9+
return Promise.resolve()
10+
.then(() => ng('generate', 'module', 'foo'))
11+
.then(() => ng('generate', 'component', 'foo'))
12+
.then(() => expectFileToMatch(modulePath, /import { FooComponent } from '.\/foo.component'/));
13+
}

0 commit comments

Comments
 (0)