Skip to content

Commit e5237f2

Browse files
committed
chore: add missing route-based code to route blueprints
1 parent 2c2767a commit e5237f2

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<p>
22
<%= dasherizedModuleName %> Works!
3-
</p>
3+
</p><% if (route) { %>
4+
<router-outlet></router-outlet><% } %>

addon/ng2/blueprints/component/files/__path__/__name__.component.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,27 @@ import {
1010
ComponentFixture,
1111
TestComponentBuilder
1212
} from 'angular2/testing';
13-
import {provide} from 'angular2/core';
13+
import {provide} from 'angular2/core';<% if (route) { %>
14+
import {Router, RouteParams} from 'angular2/router';<% } %>
1415
import {<%= classifiedModuleName %>Component} from './<%= dasherizedModuleName %>.component';
16+
<% if (route) { %>
17+
class MockRouter {
18+
registerPrimaryOutlet() { }
19+
}
1520

16-
describe('<%= classifiedModuleName %> Component', () => {
21+
class MockRouteParams {
22+
get() { return 1; }
23+
}<% } %>
1724

25+
describe('<%= classifiedModuleName %> Component', () => {
26+
<% if (route) { %>
27+
beforeEachProviders(() => [
28+
provide(Router, { useClass: MockRouter }),
29+
provide(RouteParams, { useClass: MockRouteParams }),
30+
]);
31+
<% } else { %>
1832
beforeEachProviders((): any[] => []);
19-
20-
33+
<% } %>
2134
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
2235
return tcb.createAsync(<%= classifiedModuleName %>Component).then((fixture: ComponentFixture) => {
2336
fixture.detectChanges();

addon/ng2/blueprints/component/files/__path__/__name__.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import {Component, OnInit} from 'angular2/core';
1+
import {Component, OnInit} from 'angular2/core';<% if (route) { %>
2+
import {RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from 'angular2/router';<% } %>
23

34
@Component({
45
moduleId: __moduleName,
56
selector: '<%= dasherizedModuleName %>',
67
templateUrl: '<%= dasherizedModuleName %>.component.html',
7-
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']
8-
})
8+
styleUrls: ['<%= dasherizedModuleName %>.component.<%= styleExt %>']<% if (route) { %>,
9+
directives: [ROUTER_DIRECTIVES]<% } %>
10+
})<% if (route) { %>
11+
@RouteConfig([
12+
])<% } %>
913
export class <%= classifiedModuleName %>Component implements OnInit {
1014

1115
constructor() {}

addon/ng2/blueprints/component/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports = {
4242
return {
4343
dynamicPath: this.dynamicPath.dir.replace(this.dynamicPath.appRoot, ''),
4444
flat: options.flat,
45+
route: options.route,
4546
styleExt: this.styleExt,
4647
isLazyRoute: !!options.isLazyRoute,
4748
isAppComponent: !!options.isAppComponent

0 commit comments

Comments
 (0)