2 |
欢迎使用本系统
3 |
4 |
全局state中loading:{{loading}}
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/app/containers/home/index.ts:
--------------------------------------------------------------------------------
1 | import { CommonModule } from '@angular/common';
2 | import { FormsModule } from '@angular/forms';
3 | import { NgModule } from '@angular/core';
4 | import { RouterModule } from '@angular/router';
5 |
6 | import { Home } from './home.component';
7 | import {HomeService} from './home.service';
8 | console.log('`Home` bundle loaded asynchronously');
9 | export const routes = [
10 | { path: '', component: Home, pathMatch: 'full' }
11 | ];
12 |
13 | @NgModule({
14 | declarations: [
15 | Home
16 | ],
17 | imports: [
18 | CommonModule,
19 | FormsModule,
20 | RouterModule.forChild(routes),
21 | ],
22 | providers: [
23 | HomeService
24 | ]
25 | })
26 | export default class AboutModule {
27 | static routes = routes;
28 | }
29 |
--------------------------------------------------------------------------------
/src/app/containers/home/title/index.ts:
--------------------------------------------------------------------------------
1 | export * from './title.service';
2 |
--------------------------------------------------------------------------------
/src/app/containers/home/title/title.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { Http } from '@angular/http';
3 |
4 | @Injectable()
5 | export class Title {
6 | value = 'Angular 2';
7 | constructor(public http: Http) {
8 |
9 | }
10 |
11 | getData() {
12 | console.log('Title#getData(): Get Data');
13 | // return this.http.get('/assets/data.json')
14 | // .map(res => res.json());
15 | return {
16 | value: 'AngularClass'
17 | };
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/app/containers/home/title/title.spec.ts:
--------------------------------------------------------------------------------
1 | import {
2 | inject,
3 | TestBed
4 | } from '@angular/core/testing';
5 | import { Component } from '@angular/core';
6 | import {
7 | BaseRequestOptions,
8 | ConnectionBackend,
9 | Http
10 | } from '@angular/http';
11 | import { MockBackend } from '@angular/http/testing';
12 |
13 | import { Title } from './title.service';
14 |
15 | describe('Title', () => {
16 | beforeEach(() => TestBed.configureTestingModule({
17 | providers: [
18 | BaseRequestOptions,
19 | MockBackend,
20 | {
21 | provide: Http,
22 | useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
23 | return new Http(backend, defaultOptions);
24 | },
25 | deps: [MockBackend, BaseRequestOptions]
26 | },
27 | Title
28 | ]}));
29 |
30 | it('should have http', inject([ Title ], (title: Title) => {
31 | expect(!!title.http).toEqual(true);
32 | }));
33 |
34 | it('should get data from the server', inject([ Title ], (title: Title) => {
35 | spyOn(console, 'log');
36 | expect(console.log).not.toHaveBeenCalled();
37 |
38 | title.getData();
39 | expect(console.log).toHaveBeenCalled();
40 | expect(title.getData()).toEqual({ value: 'AngularClass' });
41 | }));
42 |
43 | });
44 |
--------------------------------------------------------------------------------
/src/app/containers/home/x-large/index.ts:
--------------------------------------------------------------------------------
1 | export * from './x-large.directive';
2 |
--------------------------------------------------------------------------------
/src/app/containers/home/x-large/x-large.directive.ts:
--------------------------------------------------------------------------------
1 | import { Component, Directive, ElementRef, Renderer } from '@angular/core';
2 | /*
3 | * Directive
4 | * XLarge is a simple directive to show how one is made
5 | */
6 | @Directive({
7 | selector: '[x-large]' // using [ ] means selecting attributes
8 | })
9 | export class XLarge {
10 | constructor(element: ElementRef, renderer: Renderer) {
11 | // simple DOM manipulation to set font size to x-large
12 | // `nativeElement` is the direct reference to the DOM element
13 | // element.nativeElement.style.fontSize = 'x-large';
14 |
15 | // for server/webworker support use the renderer
16 | renderer.setElementStyle(element.nativeElement, 'fontSize', 'x-large');
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/app/containers/home/x-large/x-large.spec.ts:
--------------------------------------------------------------------------------
1 | import {
2 | fakeAsync,
3 | inject,
4 | tick,
5 | TestBed
6 | } from '@angular/core/testing';
7 | import { Component } from '@angular/core';
8 | import { BaseRequestOptions, Http } from '@angular/http';
9 | import { By } from '@angular/platform-browser/src/dom/debug/by';
10 | import { MockBackend } from '@angular/http/testing';
11 |
12 | // Load the implementations that should be tested
13 | import { XLarge } from './x-large.directive';
14 |
15 | describe('x-large directive', () => {
16 | // Create a test component to test directives
17 | @Component({
18 | template: '