Skip to content

Commit dfc40b3

Browse files
committed
Updated AngularJS application.
Included node.js libraries.
1 parent 08cce02 commit dfc40b3

7 files changed

Lines changed: 118 additions & 59 deletions

File tree

samples/features/json/angularjs/dotnet-tour-of-heroes/README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ To run this sample, you need the following prerequisites.
3131

3232
1. SQL Server 2016 (or higher) or an Azure SQL Database
3333
2. Visual Studio 2015 Update 3 (or higher) or Visual Studio Code Editor with the ASP.NET Core 1.0 (or higher)
34+
3. .NET Core SDK for [Windows](https://go.microsoft.com/fwlink/?LinkID=827524) or other [operating systems](https://www.microsoft.com/net/core)
35+
4. Node.js installation [Node.js](https://nodejs.org/en/download/)
3436

3537
**Azure prerequisites:**
3638

@@ -44,9 +46,7 @@ To run this sample, you need the following prerequisites.
4446

4547
2. From SQL Server Management Studio or Sql Server Data Tools connect to your SQL Server 2016 or Azure SQL database and execute [sql-scripts/setup.sql](sql-scripts/setup.sql) script that will create and populate **Hero** table.
4648

47-
3. From Visual Studio 2015, open the **HeroesApp.xproj** file from the root directory. Restore packages using right-click menu on the project in Visual Studio and by choosing Restore Packages item. As an alternative, you may run **dotnet restore** from the command line (from the root folder of application).
48-
49-
4. Add a connection string in appsettings.json or appsettings.development.json file. An example of the content of appsettings.development.json is shown in the following configuration:
49+
3. Add a connection string in appsettings.json or appsettings.development.json file. An example of the content of appsettings.development.json is shown in the following configuration:
5050

5151
```
5252
{
@@ -60,16 +60,28 @@ If your database is hosted on Azure you can add something like:
6060
```
6161
{
6262
"ConnectionStrings": {
63-
"HeroDb": "Server=<<SERVER>>.database.windows.net;Database=CommentsDb;User Id=<<USER>>;Password=<<PASSWORD>>"
63+
"HeroDb": "Server=<<SERVER>>.database.windows.net;Database=HeroDb;User Id=<<USER>>;Password=<<PASSWORD>>"
6464
}
6565
}
6666
```
6767

6868
### Build and run sample
6969

70-
1. Build project using **dotnet build** command executed from command line (from project root folder) or using Visual Studion 2015.
71-
2. Run the sample app using F5 or Ctrl+F5 in Visual Studio 2015, or using **dotnet run** executed in the command prompt of the project root folder.
72-
3. Open /index.html Url to see heroes from database. See more details about functionalities in [AngularJS Heroes sample app](https://angular.io/docs/ts/latest/tutorial/)
70+
1. Restore NugetPackages using **dotnet restore** command. This command will create **project.lock.json** file.
71+
2. Restore npm packages using **npm install** command lines. This command will download packages in **node_modules** folder.
72+
3. Build project using **dotnet build** command executed from command line (from project root folder) or using Visual Studion 2015.
73+
4. Run the sample app using **dotnet run** executed in the command prompt of the project root folder.
74+
75+
Sequence of commands is:
76+
```
77+
npm install
78+
dotnet restore
79+
dotnet build
80+
dotnet run
81+
```
82+
83+
### Run the app
84+
. Open /index.html Url to see heroes from database. See more details about functionalities in [AngularJS Heroes sample app](https://angular.io/docs/ts/latest/tutorial/)
7385

7486
<a name=sample-details></a>
7587

samples/features/json/angularjs/dotnet-tour-of-heroes/Startup.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
using Belgrade.SqlClient.SqlDb;
33
using Microsoft.AspNetCore.Builder;
44
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Http;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.FileProviders;
79
using Microsoft.Extensions.Logging;
810
using System.Data.SqlClient;
11+
using System.IO;
912

1013
namespace AngularHeroApp
1114
{
@@ -46,6 +49,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
4649

4750
app.UseMvc();
4851
app.UseStaticFiles();
52+
53+
// Expose node_modules as virtual folder
54+
// becasue AngularJS uses some libraries from node_modules folder.
55+
app.UseStaticFiles(new StaticFileOptions()
56+
{
57+
FileProvider =
58+
new PhysicalFileProvider(
59+
Path.Combine(Directory.GetCurrentDirectory(), @"node_modules")),
60+
RequestPath = new PathString("/node_modules")
61+
});
4962
}
5063
}
5164
}

samples/features/json/angularjs/dotnet-tour-of-heroes/wwwroot/index.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
<link rel="stylesheet" href="styles.css">
99

10-
<!-- Polyfill(s) for older browsers -->
11-
<script src="libs/core-js/shim.min.js"></script>
12-
<script src="libs/zone.js/zone.js"></script>
13-
<script src="libs/reflect-metadata/reflect.js"></script>
14-
<script src="libs/systemjs/system.src.js"></script>
15-
<!-- 2. Configure SystemJS -->
16-
<script src="systemjs.config.js"></script>
17-
<script>
18-
System.import('app').catch(function(err){ console.error(err); });
10+
<!-- IE required polyfills, in this exact order -->
11+
<script src="node_modules/core-js/client/shim.min.js"></script>
12+
<script src="node_modules/zone.js/dist/zone.js"></script>
13+
<script src="node_modules/reflect-metadata/Reflect.js"></script>
14+
<script src="node_modules/systemjs/dist/system.src.js"></script>
15+
16+
<script>
17+
System.import('system-config.js').then(function () {
18+
System.import('main');
19+
}).catch(console.error.bind(console));
1920
</script>
2021
</head>
2122

samples/features/json/angularjs/dotnet-tour-of-heroes/wwwroot/system-config.js

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/features/json/angularjs/dotnet-tour-of-heroes/wwwroot/system-config.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* System configuration for Angular samples
3+
* Adjust as necessary for your application needs.
4+
*/
5+
declare var System: any;
6+
7+
System.config({
8+
paths: {
9+
// paths serve as alias
10+
'npm:': 'node_modules/'
11+
},
12+
// map tells the System loader where to look for things
13+
map: {
14+
// our app is within the app folder
15+
'app': 'app',
16+
'main': 'app/main.js',
17+
18+
// angular bundles
19+
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
20+
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
21+
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
22+
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
23+
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
24+
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
25+
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
26+
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
27+
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
28+
29+
// other libraries
30+
'rxjs': 'npm:rxjs',
31+
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
32+
},
33+
// packages tells the System loader how to load when no filename and/or no extension
34+
packages: {
35+
'app': { main: './main.js', defaultExtension: 'js' },
36+
'api' : { defaultExtension : 'js' },
37+
'rxjs': { defaultExtension: 'js' },
38+
39+
// barrels
40+
// 'app/core': { main: 'index'},
41+
// 'app/models': { main: 'index'},
42+
}
43+
});

samples/features/json/angularjs/dotnet-tour-of-heroes/wwwroot/systemjs.config.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)