Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: several small fixes/improvements/refactorings for the guides #21589

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const routes: Routes = [

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: []
exports: [RouterModule]
})
export class CustomersRoutingModule { }
// #enddocregion customers-routing-module
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@ import { Routes, RouterModule } from '@angular/router';
// #docregion orders-routing-module-detail
import { OrderListComponent } from './order-list/order-list.component';


const routes: Routes = [
{
path: '',
component: OrderListComponent
}
];

// #enddocregion orders-routing-module-detail

@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [
RouterModule
]
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class OrdersRoutingModule { }
// #enddocregion orders-routing-module
19 changes: 11 additions & 8 deletions aio/content/examples/ngmodules/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

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

/* Feature Modules */
import { ContactModule } from './contact/contact.module';
import { CoreModule } from './core/core.module';
import { ContactModule } from './contact/contact.module';
// #docregion import-for-root
import { CoreModule } from './core/core.module';
// #enddocregion import-for-root

/* Routing Module */
import { AppRoutingModule } from './app-routing.module';



// #docregion import-for-root
@NgModule({
declarations: [
AppComponent
],
// #docregion import-for-root
imports: [
BrowserModule,
ContactModule,
Expand All @@ -28,6 +26,11 @@ import { AppRoutingModule } from './app-routing.module';
],
// #enddocregion import-for-root
providers: [],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
// #docregion import-for-root
})
export class AppModule { }
// #enddocregion import-for-root
30 changes: 16 additions & 14 deletions aio/content/examples/ngmodules/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
/* tslint:disable:member-ordering no-unused-variable */
// #docregion whole-core-module
import {
ModuleWithProviders, NgModule,
Optional, SkipSelf } from '@angular/core';
// #docregion whole-core-module
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';

import { CommonModule } from '@angular/common';
import { CommonModule } from '@angular/common';

import { TitleComponent } from './title.component';
import { UserService } from './user.service';
import { TitleComponent } from './title.component';
// #docregion user-service
import { UserService } from './user.service';
// #enddocregion user-service
import { UserServiceConfig } from './user.service';


// #docregion user-service
@NgModule({
// #enddocregion user-service
imports: [ CommonModule ],
declarations: [ TitleComponent ],
exports: [ TitleComponent ],
// #docregion user-service
providers: [ UserService ]
})
export class CoreModule {
// #docregion ctor
// #enddocregion user-service
// #docregion ctor
constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
if (parentModule) {
throw new Error(
'CoreModule is already loaded. Import it in the AppModule only');
}
}
// #enddocregion ctor

// #enddocregion ctor

// #docregion for-root
static forRoot(config: UserServiceConfig): ModuleWithProviders {
Expand All @@ -36,9 +39,8 @@ export class CoreModule {
]
};
}

// #enddocregion for-root
// #docregion user-service
}

// #enddocregion user-service
// #enddocregion whole-core-module

13 changes: 6 additions & 7 deletions aio/content/examples/providers/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import { Component, OnInit } from '@angular/core';

import { User } from './core/user';
import { UserService } from './core/user.service';
import { User, UserService } from './user.service';

// #docregion component-providers
@Component({
// #enddocregion component-providers
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
// #docregion component-providers
providers: [UserService]
})
// #enddocregion component-providers
export class AppComponent implements OnInit {
title = 'Users list';
users: User[];

constructor(private userService: UserService) { }

getUsers(): void {
this.userService.getUsers().then(users => this.users = users);
}

ngOnInit(): void {
this.getUsers();
this.userService.getUsers().then(users => this.users = users);
}

}
24 changes: 6 additions & 18 deletions aio/content/examples/providers/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
// #docplaster
// #docregion app-module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
// CoreModule provides the UserService.
import { CoreModule } from './core/core.module';
import { UserService } from './user.service';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
CoreModule
],
bootstrap: [AppComponent]
imports: [ BrowserModule ],
providers: [ UserService ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
// #enddocregion app-module
16 changes: 0 additions & 16 deletions aio/content/examples/providers/src/app/core/core.module.ts

This file was deleted.

14 changes: 0 additions & 14 deletions aio/content/examples/providers/src/app/core/mock-users.ts

This file was deleted.

15 changes: 0 additions & 15 deletions aio/content/examples/providers/src/app/core/user.service.ts

This file was deleted.

4 changes: 0 additions & 4 deletions aio/content/examples/providers/src/app/core/user.ts

This file was deleted.

28 changes: 28 additions & 0 deletions aio/content/examples/providers/src/app/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';

export class User {
id: number;
name: string;
}

@Injectable()
export class UserService {

constructor() { }

getUsers(): Promise<User[]> {
return Promise.resolve([
{ id: 1, name: 'Maria' },
{ id: 2, name: 'Alex' },
{ id: 3, name: 'Chuntao' },
{ id: 4, name: 'Béatrice' },
{ id: 5, name: 'Sarah' },
{ id: 6, name: 'Andrés' },
{ id: 7, name: 'Abdul' },
{ id: 8, name: 'Pierre' },
{ id: 9, name: 'Jiao' },
{ id: 10, name: 'Seth' }
]);
}

}