Skip to content

Commit 6e22a35

Browse files
Merge pull request #2 from angular-redux/chore/form-example
Chore/form example
2 parents efbe319 + 9b1db6e commit 6e22a35

17 files changed

+6626
-24
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
},
1414
"private": true,
1515
"dependencies": {
16+
"@angular-redux/form": "^5.1.0-beta.0",
17+
"@angular-redux/router": "2.0.0-alpha.3",
18+
"@angular-redux/store": "^5.1.0",
1619
"@angular/common": "^2.3.1",
1720
"@angular/compiler": "^2.3.1",
1821
"@angular/core": "^2.3.1",
@@ -21,8 +24,6 @@
2124
"@angular/platform-browser": "^2.3.1",
2225
"@angular/platform-browser-dynamic": "^2.3.1",
2326
"@angular/router": "^3.3.1",
24-
"@angular-redux/store": "^5.1.0",
25-
"@angular-redux/router": "2.0.0-alpha.3",
2627
"core-js": "^2.4.1",
2728
"redux": "^3.6.0",
2829
"redux-observable": "^0.12.2",

src/app/app.component.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@
33
border-radius: 3px;
44
padding: 5px;
55
}
6+
7+
content {
8+
display: block;
9+
padding: 10px;
10+
border: solid gray 1px;
11+
border-radius: 5px;
12+
margin-top: 1rem;
13+
}

src/app/app.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ <h1>
44
<nav>
55
<a routerLink="/elephants" routerLinkActive="active">Elephants</a>
66
<a routerLink="/lions" routerLinkActive="active">Lions</a>
7+
<a routerLink="/feedback" routerLinkActive="active">Feedback</a>
78
</nav>
8-
<router-outlet></router-outlet>
9+
10+
<content>
11+
<router-outlet></router-outlet>
12+
</content>

src/app/app.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component } from '@angular/core';
22
import { NgRedux, DevToolsExtension } from '@angular-redux/store';
33
import { NgReduxRouter, routerReducer } from '@angular-redux/router';
4+
import { provideReduxForms, composeReducers, defaultFormReducer } from '@angular-redux/form';
45
import { Action, combineReducers } from 'redux';
56
import { createEpicMiddleware, combineEpics } from 'redux-observable';
67

@@ -27,11 +28,13 @@ export class AppComponent {
2728
elephantsEpics: ElephantsEpics,
2829
lionsEpics: LionsEpics
2930
) {
30-
const rootReducer = combineReducers({
31-
elephants: elephantsReducer,
32-
lions: lionsReducer,
33-
router: routerReducer,
34-
});
31+
const rootReducer = composeReducers(
32+
defaultFormReducer(),
33+
combineReducers({
34+
elephants: elephantsReducer,
35+
lions: lionsReducer,
36+
router: routerReducer,
37+
}));
3538

3639
ngRedux.configureStore(
3740
rootReducer,
@@ -41,7 +44,8 @@ export class AppComponent {
4144
createEpicMiddleware(combineEpics(...lionsEpics.epics)),
4245
],
4346
devTools.isEnabled() ? [ devTools.enhancer() ] : null);
44-
ngReduxRouter.initialize(/* args */);
47+
ngReduxRouter.initialize();
48+
provideReduxForms(ngRedux);
4549
}
4650

4751
ngOnInit() {

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AppActions } from './app.actions';
1212

1313
import { ElephantsModule } from './elephants/elephants.module';
1414
import { LionsModule } from './lions/lions.module';
15+
import { FeedbackModule } from './feedback/feedback.module';
1516

1617
@NgModule({
1718
declarations: [ AppComponent ],
@@ -24,6 +25,7 @@ import { LionsModule } from './lions/lions.module';
2425
NgReduxRouterModule,
2526
ElephantsModule,
2627
LionsModule,
28+
FeedbackModule,
2729
],
2830
providers: [ AppActions ],
2931
bootstrap: [ AppComponent ]

src/app/app.routes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { ElephantListComponent } from './elephants/elephant-list/elephant-list.component';
22
import { LionListComponent } from './lions/lion-list/lion-list.component';
3+
import { FeedbackFormComponent } from './feedback/feedback-form/feedback-form.component';
34

45
export const appRoutes = [
6+
{ path: '', redirectTo: '/elephants', pathMatch: 'full' },
57
{ path: 'elephants', component: ElephantListComponent },
6-
{ path: 'lions', component: LionListComponent }
8+
{ path: 'lions', component: LionListComponent },
9+
{ path: 'feedback', component: FeedbackFormComponent },
710
];

src/app/elephants/elephant-list/elephant-list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { select } from '@angular-redux/store';
99
export class ElephantListComponent {
1010
// Shorthand for
1111
// constructor(ngRedux: NgRedux { this.elephants$ = ngRedux.select('elephants'); })
12-
@select() elephants$
12+
@select() readonly elephants$
1313

1414
// Since we're observing an array of items, we need to set up a 'trackBy'
1515
// parameter so Angular doesn't tear down and rebuild the list's DOM every

src/app/elephants/elephants.actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Action } from 'redux';
33

44
@Injectable()
55
export class ElephantsActions {
6-
static LOAD_SUCCEEDED = 'LOAD_SUCCEEDED(ELEPHANTS)';
7-
static LOAD_FAILED = 'LOAD_SUCCEEDED(ELEPHANTS)';
6+
static readonly LOAD_SUCCEEDED = 'LOAD_SUCCEEDED(ELEPHANTS)';
7+
static readonly LOAD_FAILED = 'LOAD_FAILED(ELEPHANTS)';
88

99
loadSucceeded(payload) {
1010
return {

src/app/elephants/elephants.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { Http } from '@angular/http';
33
import 'rxjs/add/operator/map';
44

55
// A fake API on the internets.
6-
const BASE_URL = 'http://jsonplaceholder.typicode.com';
6+
const ELEPHANTS_URL = 'http://www.mocky.io/v2/588d70ad100000e50f2d2983';
77

88
@Injectable()
99
export class ElephantsService {
1010
constructor(private http: Http) {}
1111

1212
getAll() {
13-
return this.http.get(BASE_URL + '/users')
13+
return this.http.get(ELEPHANTS_URL)
1414
.map(resp => resp.json())
1515
.map(records => records.map(
1616
record => ({
17-
animalType: 'Elephant',
18-
name: record.name.split(' ')[0],
17+
animalType: record.type,
18+
name: record.name,
1919
})));
2020
}
2121
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
label {
2+
display: block;
3+
width: 100%;
4+
margin-bottom: 1rem;
5+
}
6+
7+
input, textarea {
8+
display: block;
9+
width: 95%;
10+
padding: 5px;
11+
border: solid gray 1px;
12+
border-radius: 5px;
13+
}
14+
15+
textarea {
16+
height: 250px;
17+
}
18+
19+
.footnote {
20+
font-style: italic;
21+
}

0 commit comments

Comments
 (0)