[英]Consuming web api using angular js with c#
I want to consume web api using AngularJs to create a dashboard with c# . 我想使用AngularJs使用Web API来使用c#创建仪表板。 I succeed to consume the web api but when I want to add angular Js to create my Dashboard nothing appears.
我成功使用了Web api,但是当我想添加角度Js来创建仪表板时,什么也没出现。 I can't figure out what is the problem.
我不知道是什么问题。
script.js script.js
var app = angular.module("DemandeApp", []); app.controller("DemCreditController", function ($scope, $http) {
$http.get("http://localhost:2573/api/demandes")
.then(function (response) {
$scope.labels = [];
$scope.data = [];
angular.forEach(response.data, function (value, key) {
$scope.labels[key] = value.libelle;
$scope.data[key] = value.quantite;
}
);
});
});
index.html : index.html:
<body ng-app="DemandeApp">
<div ng-controller="DemCreditController">
<canvas id="pie" class="chart chart-pie"
chart-data="data" chart-labels="labels" ></canvas>
</div></body>
You can try like the below code to push the data to your array, 您可以尝试使用下面的代码将数据推送到数组中,
$http.get("http://localhost:2573/api/demandes")
.then(function (response) {
$scope.labels = [];
$scope.data = [];
angular.forEach(response.data, function (value, key) {
$scope.labels.push(value.libelle);
$scope.data.push(value.quantite);
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.