Skip to content

Commit ad4a61f

Browse files
Broccofilipesilva
authored andcommitted
bug(generate): directive selectors are now camelCase
Fixes #1216 Close #2323
1 parent a611a40 commit ad4a61f

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

packages/angular-cli/blueprints/directive/files/__path__/__name__.directive.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Directive } from '@angular/core';
22

33
@Directive({
4-
selector: '[<%= rawEntityName %>]'
4+
selector: '[<%= selector %>]'
55
})
66
export class <%= classifiedModuleName %>Directive {
77

packages/angular-cli/blueprints/directive/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ module.exports = {
3131
this.project.ngConfig.apps[0].prefix) {
3232
defaultPrefix = this.project.ngConfig.apps[0].prefix;
3333
}
34-
var prefix = this.options.prefix ? defaultPrefix : '';
34+
var prefix = this.options.prefix ? `${defaultPrefix}-` : '';
3535

36-
this.rawEntityName = prefix + parsedPath.name;
36+
this.selector = stringUtils.camelize(prefix + parsedPath.name);
3737
return parsedPath.name;
3838
},
3939

4040
locals: function (options) {
4141
return {
4242
dynamicPath: this.dynamicPath.dir,
4343
flat: options.flat,
44-
rawEntityName: this.rawEntityName
44+
selector: this.selector
4545
};
4646
},
4747

tests/acceptance/generate-directive.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,15 @@ describe('Acceptance: ng generate directive', function () {
156156
expect(err).to.equal(`Invalid path: "..${path.sep}my-dir" cannot be above the "src${path.sep}app" directory`);
157157
});
158158
});
159+
160+
it('converts dash-cased-name to a camelCasedSelector', () => {
161+
const appRoot = path.join(root, 'tmp/foo');
162+
const directivePath = path.join(appRoot, 'src/app/my-dir.directive.ts');
163+
return ng(['generate', 'directive', 'my-dir'])
164+
.then(() => readFile(directivePath, 'utf-8'))
165+
.then(content => {
166+
// expect(content).matches(/selector: [app-my-dir]/m);
167+
expect(content).matches(/selector: '\[appMyDir\]'/);
168+
});
169+
});
159170
});

0 commit comments

Comments
 (0)