Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit fc2815f

Browse files
committed
docs(ngmodule): updates for clarity; breaks out CoreModule
1 parent 0a45a47 commit fc2815f

29 files changed

Lines changed: 813 additions & 284 deletions

gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,15 @@ function installExampleAngular() {
517517
var sources;
518518
var template;
519519
var libs = [
520-
'core', 'common', 'compiler',
520+
'core', 'common', 'compiler', 'compiler-cli',
521521
'platform-browser', 'platform-browser-dynamic',
522522
'forms', 'http', 'router', 'upgrade'];
523523

524524
// Like: "angular/core-builds" or "@angular/core"
525525
sources = libs.map( lib => argv.build ? `angular/${lib}-builds` : `@angular/${lib}`);
526526

527+
if (argv.build) { sources.push('@angular/tsc-wrapped');} // tsc-wrapped needed for builds
528+
527529
sources.push('@angular/router-deprecated');
528530

529531
gutil.log(`Installing Angular npm packages from ${argv.build ? 'BUILD' : 'RELEASE'}`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"protractor": "^3.0.0",
7272
"q": "^1.4.1",
7373
"tree-kill": "^1.0.0",
74-
"tslint": "^3.2.2",
74+
"tslint": "^3.15.1",
7575
"yargs": "^4.7.1"
7676
},
7777
"dependencies": {

public/docs/_examples/ngmodule/e2e-spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('NgModule', function () {
66
const gold = 'rgba(255, 215, 0, 1)';
77
const powderblue = 'rgba(176, 224, 230, 1)';
88
const lightgray = 'rgba(211, 211, 211, 1)';
9+
const white = 'rgba(0, 0, 0, 0)';
910

1011
function getCommonsSectionStruct() {
1112
const buttons = element.all(by.css('nav a'));
@@ -55,7 +56,7 @@ describe('NgModule', function () {
5556
}
5657

5758
// tests
58-
function appTitleTests(color: string) {
59+
function appTitleTests(color: string, name?: string) {
5960
return function() {
6061
it('should have a gray header', function() {
6162
const commons = getCommonsSectionStruct();
@@ -64,16 +65,16 @@ describe('NgModule', function () {
6465

6566
it('should welcome us', function () {
6667
const commons = getCommonsSectionStruct();
67-
expect(commons.subtitle.getText()).toBe('Welcome, Sam Spade');
68+
expect(commons.subtitle.getText()).toBe('Welcome, ' + (name || 'Sherlock Holmes'));
6869
});
6970
};
7071
}
7172

72-
function contactTests(color: string) {
73+
function contactTests(color: string, name?: string) {
7374
return function() {
7475
it('shows the contact\'s owner', function() {
7576
const contacts = getContactSectionStruct();
76-
expect(contacts.header.getText()).toBe('Contact of Sam Spade');
77+
expect(contacts.header.getText()).toBe('Contact of ' + (name || 'Sherlock Holmes'));
7778
});
7879

7980
it('can cycle between contacts', function () {
@@ -114,9 +115,9 @@ describe('NgModule', function () {
114115
browser.get('');
115116
});
116117

117-
describe('app-title', appTitleTests(lightgray));
118+
describe('app-title', appTitleTests(white, 'Miss Marple'));
118119

119-
describe('contact', contactTests(lightgray));
120+
describe('contact', contactTests(lightgray, 'Miss Marple'));
120121

121122
describe('crisis center', function () {
122123
beforeEach(function () {
@@ -149,7 +150,7 @@ describe('NgModule', function () {
149150

150151
it('shows a list of heroes', function() {
151152
const heroes = getHeroesSectionStruct();
152-
expect(heroes.header.getText()).toBe('Heroes of Sam Spade');
153+
expect(heroes.header.getText()).toBe('Heroes of Miss Marple');
153154
expect(heroes.title.getText()).toBe('Hero List');
154155
expect(heroes.items.count()).toBe(6);
155156
expect(heroes.items.get(0).getText()).toBe('11 - Mr. Nice');

public/docs/_examples/ngmodule/ts/app/app.module.3.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { UserService } from './user.service';
1111

1212
/* Feature Modules */
1313
import { ContactModule } from './contact/contact.module.3';
14-
15-
1614
import { routing } from './app.routing.3';
1715

1816
@NgModule({
@@ -23,9 +21,8 @@ import { routing } from './app.routing.3';
2321
routing
2422
],
2523
// #enddocregion imports
26-
27-
declarations: [ AppComponent, HighlightDirective, TitleComponent ],
2824
providers: [ UserService ],
25+
declarations: [ AppComponent, HighlightDirective, TitleComponent ],
2926
bootstrap: [ AppComponent ]
3027
})
3128
export class AppModule { }
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
// #docplaster
22
// #docregion
3+
// #docregion v4
34
import { NgModule } from '@angular/core';
45
import { BrowserModule } from '@angular/platform-browser';
56

67
/* App Root */
78
import { AppComponent } from './app.component';
89

9-
10-
11-
1210
/* Feature Modules */
1311
import { ContactModule } from './contact/contact.module';
14-
import { SharedModule } from './shared/shared.module';
15-
12+
import { CoreModule } from './core/core.module';
1613
import { routing } from './app.routing';
1714

1815
@NgModule({
16+
// #docregion import-for-root
1917
imports: [
2018
BrowserModule,
2119
ContactModule,
22-
routing,
23-
SharedModule.forRoot()
20+
// #enddocregion v4
21+
// #enddocregion
22+
// #enddocregion import-for-root
23+
/*
24+
// #docregion v4
25+
CoreModule,
26+
// #enddocregion v4
27+
*/
28+
// #docregion import-for-root
29+
// #docregion
30+
CoreModule.forRoot({userName: 'Miss Marple'}),
31+
// #docregion v4
32+
routing
2433
],
34+
// #enddocregion import-for-root
2535
declarations: [ AppComponent ],
26-
2736
bootstrap: [ AppComponent ]
2837
})
2938
export class AppModule { }
39+
// #enddocregion v4
40+
// #enddocregion

public/docs/_examples/ngmodule/ts/app/contact/contact.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Exact copy except import UserService from shared
1+
// Exact copy except import UserService from core
22
// #docregion
33
import { Component, OnInit } from '@angular/core';
44

55
import { Contact, ContactService } from './contact.service';
6-
import { UserService } from '../shared/user.service';
6+
import { UserService } from '../core/user.service';
77

88
@Component({
99
selector: 'app-contact',

public/docs/_examples/ngmodule/ts/app/contact/contact.module.3.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { routing } from './contact.routing.3';
1515
@NgModule({
1616
imports: [ CommonModule, FormsModule, routing ],
1717
declarations: [ ContactComponent, HighlightDirective, AwesomePipe ],
18-
1918
providers: [ ContactService ]
2019
})
2120
export class ContactModule { }

public/docs/_examples/ngmodule/ts/app/contact/contact.routing.3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ModuleWithProviders } from '@angular/core';
2-
import { RouterModule } from '@angular/router';
2+
import { RouterModule } from '@angular/router';
33

4-
import { ContactComponent } from './contact.component.3';
4+
import { ContactComponent } from './contact.component.3';
55

66
export const routing: ModuleWithProviders = RouterModule.forChild([
77
{ path: 'contact', component: ContactComponent}

public/docs/_examples/ngmodule/ts/app/contact/contact.routing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ModuleWithProviders } from '@angular/core';
2-
import { RouterModule } from '@angular/router';
2+
import { RouterModule } from '@angular/router';
33

4-
import { ContactComponent } from './contact.component';
4+
import { ContactComponent } from './contact.component';
55

66
// #docregion routing
77
export const routing: ModuleWithProviders = RouterModule.forChild([
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* tslint:disable:member-ordering no-unused-variable */
2+
// #docplaster
3+
// #docregion
4+
// #docregion v4
5+
import {
6+
BaseException, ModuleWithProviders,
7+
NgModule, Optional, SkipSelf } from '@angular/core';
8+
9+
import { CommonModule } from '@angular/common';
10+
11+
import { TitleComponent } from './title.component';
12+
import { UserService } from './user.service';
13+
// #enddocregion
14+
import { UserServiceConfig } from './user.service';
15+
16+
// #docregion v4
17+
@NgModule({
18+
imports: [ CommonModule ],
19+
declarations: [ TitleComponent ],
20+
exports: [ TitleComponent ],
21+
providers: [ UserService ]
22+
})
23+
export class CoreModule {
24+
// #enddocregion v4
25+
26+
// #docregion ctor
27+
constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
28+
if (parentModule) {
29+
throw new BaseException(
30+
'CoreModule is already loaded. Import it in the AppModule only');
31+
}
32+
}
33+
// #enddocregion ctor
34+
35+
// #docregion for-root
36+
static forRoot(config: UserServiceConfig): ModuleWithProviders {
37+
return {
38+
ngModule: CoreModule,
39+
providers: [
40+
{provide: UserServiceConfig, useValue: config }
41+
]
42+
};
43+
}
44+
// #enddocregion for-root
45+
// #docregion v4
46+
}
47+
// #enddocregion v4
48+
// #enddocregion

0 commit comments

Comments
 (0)