diff --git a/templates/Angular2Spa/ClientApp/components/about/about.html b/templates/Angular2Spa/ClientApp/components/about/about.html
deleted file mode 100644
index bbdd3b1..0000000
--- a/templates/Angular2Spa/ClientApp/components/about/about.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
About
-
-Use this area to provide additional information.
diff --git a/templates/Angular2Spa/ClientApp/components/about/about.ts b/templates/Angular2Spa/ClientApp/components/about/about.ts
deleted file mode 100644
index 0f9bbf7..0000000
--- a/templates/Angular2Spa/ClientApp/components/about/about.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import * as ng from 'angular2/core';
-
-@ng.Component({
- selector: 'about'
-})
-@ng.View({
- template: require('./about.html')
-})
-export class About {
-}
diff --git a/templates/Angular2Spa/ClientApp/components/app/app.ts b/templates/Angular2Spa/ClientApp/components/app/app.ts
index f98b3b7..1cd9a19 100644
--- a/templates/Angular2Spa/ClientApp/components/app/app.ts
+++ b/templates/Angular2Spa/ClientApp/components/app/app.ts
@@ -1,9 +1,9 @@
import * as ng from 'angular2/core';
import * as router from 'angular2/router';
import { Http, HTTP_BINDINGS } from 'angular2/http';
-import { NavMenu } from '../nav-menu/nav-menu.ts';
-import { Home } from '../home/home.ts';
-import { About } from '../about/about';
+import { NavMenu } from '../nav-menu/nav-menu';
+import { Home } from '../home/home';
+import { FetchData } from '../fetch-data/fetch-data';
import { Counter } from '../counter/counter';
@ng.Component({
@@ -11,8 +11,8 @@ import { Counter } from '../counter/counter';
})
@router.RouteConfig([
{ path: '/', component: Home, name: 'Home' },
- { path: '/about', component: About, name: 'About' },
- { path: '/counter', component: Counter, name: 'Counter' }
+ { path: '/counter', component: Counter, name: 'Counter' },
+ { path: '/fetch-data', component: FetchData, name: 'FetchData' }
])
@ng.View({
template: require('./app.html'),
diff --git a/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.html b/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.html
new file mode 100644
index 0000000..d7c78e8
--- /dev/null
+++ b/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.html
@@ -0,0 +1,24 @@
+Weather forecast
+
+This component demonstrates fetching data from the server.
+
+Loading...
+
+
+
+
+ | Date |
+ Temp. (C) |
+ Temp. (F) |
+ Summary |
+
+
+
+
+ | {{ forecast.dateFormatted }} |
+ {{ forecast.temperatureC }} |
+ {{ forecast.temperatureF }} |
+ {{ forecast.summary }} |
+
+
+
diff --git a/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.ts b/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.ts
new file mode 100644
index 0000000..111b5b3
--- /dev/null
+++ b/templates/Angular2Spa/ClientApp/components/fetch-data/fetch-data.ts
@@ -0,0 +1,27 @@
+import * as ng from 'angular2/core';
+import fetch from 'isomorphic-fetch';
+
+@ng.Component({
+ selector: 'fetch-data'
+})
+@ng.View({
+ template: require('./fetch-data.html')
+})
+export class FetchData {
+ public forecasts: WeatherForecast[];
+
+ constructor() {
+ fetch('/api/SampleData/WeatherForecasts')
+ .then(response => response.json())
+ .then((data: WeatherForecast[]) => {
+ this.forecasts = data;
+ });
+ }
+}
+
+interface WeatherForecast {
+ dateFormatted: string;
+ temperatureC: number;
+ temperatureF: number;
+ summary: string;
+}
diff --git a/templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.html b/templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.html
index a86ad63..adaf268 100644
--- a/templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.html
+++ b/templates/Angular2Spa/ClientApp/components/nav-menu/nav-menu.html
@@ -23,7 +23,7 @@
-
+
Fetch data
diff --git a/templates/Angular2Spa/Controllers/SampleDataController.cs b/templates/Angular2Spa/Controllers/SampleDataController.cs
new file mode 100644
index 0000000..a809d45
--- /dev/null
+++ b/templates/Angular2Spa/Controllers/SampleDataController.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNet.Mvc;
+
+namespace WebApplicationBasic.Controllers
+{
+ [Route("api/[controller]")]
+ public class SampleDataController : Controller
+ {
+ private static string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ [HttpGet, Route("[action]")]
+ public IEnumerable WeatherForecasts()
+ {
+ var rng = new Random();
+ return Enumerable.Range(1, 5).Select(index => new WeatherForecast
+ {
+ DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
+ TemperatureC = rng.Next(-20, 55),
+ Summary = Summaries[rng.Next(Summaries.Length)]
+ });
+ }
+
+ public class WeatherForecast
+ {
+ public string DateFormatted { get; set; }
+ public int TemperatureC { get; set; }
+ public string Summary { get; set; }
+
+ public int TemperatureF
+ {
+ get
+ {
+ return 32 + (int)(this.TemperatureC / 0.5556);
+ }
+ }
+ }
+ }
+}
diff --git a/templates/Angular2Spa/Startup.cs b/templates/Angular2Spa/Startup.cs
index 0152b3e..bfa5bfb 100755
--- a/templates/Angular2Spa/Startup.cs
+++ b/templates/Angular2Spa/Startup.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNet.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
+using Newtonsoft.Json.Serialization;
namespace WebApplicationBasic
{
@@ -28,7 +29,10 @@ namespace WebApplicationBasic
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
- services.AddMvc();
+ services.AddMvc().AddJsonOptions(options =>
+ {
+ options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
+ });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
diff --git a/templates/Angular2Spa/package.json b/templates/Angular2Spa/package.json
index 344ee21..d864e55 100644
--- a/templates/Angular2Spa/package.json
+++ b/templates/Angular2Spa/package.json
@@ -28,6 +28,7 @@
"babel-core": "^6.5.2",
"es6-shim": "^0.33.13",
"es7-reflect-metadata": "^1.5.5",
+ "isomorphic-fetch": "^2.2.1",
"reflect-metadata": "^0.1.2",
"rxjs": "^5.0.0-beta.2",
"zone.js": "^0.5.15"
diff --git a/templates/Angular2Spa/tsd.json b/templates/Angular2Spa/tsd.json
index 79fb09e..7520fb8 100644
--- a/templates/Angular2Spa/tsd.json
+++ b/templates/Angular2Spa/tsd.json
@@ -7,6 +7,9 @@
"installed": {
"requirejs/require.d.ts": {
"commit": "dade4414712ce84e3c63393f1aae407e9e7e6af7"
+ },
+ "isomorphic-fetch/isomorphic-fetch.d.ts": {
+ "commit": "4d2d0653003a4d1df4d7c68054cce4f4ace58bdf"
}
}
}
diff --git a/templates/Angular2Spa/typings/isomorphic-fetch/isomorphic-fetch.d.ts b/templates/Angular2Spa/typings/isomorphic-fetch/isomorphic-fetch.d.ts
new file mode 100644
index 0000000..84e4c4b
--- /dev/null
+++ b/templates/Angular2Spa/typings/isomorphic-fetch/isomorphic-fetch.d.ts
@@ -0,0 +1,119 @@
+// Type definitions for isomorphic-fetch
+// Project: https://github.com/matthew-andrews/isomorphic-fetch
+// Definitions by: Todd Lucas
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
+
+declare enum RequestContext {
+ "audio", "beacon", "cspreport", "download", "embed", "eventsource",
+ "favicon", "fetch", "font", "form", "frame", "hyperlink", "iframe",
+ "image", "imageset", "import", "internal", "location", "manifest",
+ "object", "ping", "plugin", "prefetch", "script", "serviceworker",
+ "sharedworker", "subresource", "style", "track", "video", "worker",
+ "xmlhttprequest", "xslt"
+}
+declare enum RequestMode { "same-origin", "no-cors", "cors" }
+declare enum RequestCredentials { "omit", "same-origin", "include" }
+declare enum RequestCache {
+ "default", "no-store", "reload", "no-cache", "force-cache",
+ "only-if-cached"
+}
+declare enum ResponseType { "basic", "cors", "default", "error", "opaque" }
+
+declare type HeaderInit = Headers | Array;
+declare type BodyInit = Blob | FormData | string;
+declare type RequestInfo = Request | string;
+
+interface RequestInit {
+ method?: string;
+ headers?: HeaderInit | { [index: string]: string };
+ body?: BodyInit;
+ mode?: string | RequestMode;
+ credentials?: string | RequestCredentials;
+ cache?: string | RequestCache;
+}
+
+interface IHeaders {
+ get(name: string): string;
+ getAll(name: string): Array;
+ has(name: string): boolean;
+}
+
+declare class Headers implements IHeaders {
+ append(name: string, value: string): void;
+ delete(name: string):void;
+ get(name: string): string;
+ getAll(name: string): Array;
+ has(name: string): boolean;
+ set(name: string, value: string): void;
+}
+
+interface IBody {
+ bodyUsed: boolean;
+ arrayBuffer(): Promise;
+ blob(): Promise;
+ formData(): Promise;
+ json(): Promise;
+ json(): Promise;
+ text(): Promise;
+}
+
+declare class Body implements IBody {
+ bodyUsed: boolean;
+ arrayBuffer(): Promise;
+ blob(): Promise;
+ formData(): Promise;
+ json(): Promise;
+ json(): Promise;
+ text(): Promise;
+}
+
+interface IRequest extends IBody {
+ method: string;
+ url: string;
+ headers: Headers;
+ context: string | RequestContext;
+ referrer: string;
+ mode: string | RequestMode;
+ credentials: string | RequestCredentials;
+ cache: string | RequestCache;
+}
+
+declare class Request extends Body implements IRequest {
+ constructor(input: string | Request, init?: RequestInit);
+ method: string;
+ url: string;
+ headers: Headers;
+ context: string | RequestContext;
+ referrer: string;
+ mode: string | RequestMode;
+ credentials: string | RequestCredentials;
+ cache: string | RequestCache;
+}
+
+interface IResponse extends IBody {
+ url: string;
+ status: number;
+ statusText: string;
+ ok: boolean;
+ headers: IHeaders;
+ type: string | ResponseType;
+ size: number;
+ timeout: number;
+ redirect(url: string, status: number): IResponse;
+ error(): IResponse;
+ clone(): IResponse;
+}
+
+interface IFetchStatic {
+ Promise: any;
+ Headers: IHeaders
+ Request: IRequest;
+ Response: IResponse;
+ (url: string | IRequest, init?: RequestInit): Promise;
+}
+
+declare module "isomorphic-fetch" {
+ export default IFetchStatic;
+}
+
+declare var fetch: IFetchStatic;
diff --git a/templates/Angular2Spa/typings/tsd.d.ts b/templates/Angular2Spa/typings/tsd.d.ts
index e7d781f..707ed4f 100644
--- a/templates/Angular2Spa/typings/tsd.d.ts
+++ b/templates/Angular2Spa/typings/tsd.d.ts
@@ -1,2 +1,3 @@
///
+///