Angular2 appel ASP.NET Web API
Je suis un total newbie Angulaire/Angular2, et peut-être que je vais entrer dans trop de profondeur de l'eau.... mais je vais essayer d'afficher le résultat à partir d'une API Web du contrôleur à l'aide angulaire...
Pour l'instant j'ai:
de démarrage.ts:
import {bootstrap} from 'angular2/platform/browser'
import {HTTP_PROVIDERS} from 'angular2/http'
import {AppComponent} from './app'
bootstrap(AppComponent, [HTTP_PROVIDERS]);
app.ts:
import {Component} from 'angular2/core';
import {Http} from 'angular2/http';
@Component({
selector: 'my-app',
template: '{{title}}'
})
export class AppComponent {
http: Http;
public title;
constructor(http: Http) {
this.title = 'Loading list';
this.http = http;
}
}
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Angular 2 with ASP.NET 5</title>
<link href="libs/css/bootstrap.css" />
<!-- 1. Load libraries -->
<script src="libs/es6-shim.min.js"></script>
<script src="libs/system-polyfills.js"></script>
<script src="libs/shims_for_IE.js"></script>
<script src="libs/angular2-polyfills.js"></script>
<script src="libs/system.js"></script>
<script src="libs/rx.js"></script>
<script src="libs/angular2.dev.js"></script>
<script src="libs/http.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
appScripts: {
defaultExtension: 'js'
}
}
});
</script>
<script>
System.import('appScripts/boot')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<h2>Device list 1</h2>
<my-app>Loading...</my-app>
</body>
</html>
DeciveController.cs
[Route("[controller]")]
public class DevicesController
{
[HttpGet]
public object Get()
{
return new[] { new { id= "1", name = "Raspberry 1" },
new {id="2", name = "Raspberry 2" }};
}
}
mais je ne vois pas comment appeler le contrôleur....
Toute aide serait grandement apprécié...
Vous devez vous connecter pour publier un commentaire.
Je vous montre sans l'aide d'un service externe. plus tard, lorsque vous vous déplacez, vous apprendrez ce qu'est le service en Angular2.