如何使用mvc中的angularjs读取文本文件中存在的json数据 [英] how to read the json data which is present in text file using angularjs in mvc
问题描述
任何请告诉我如何使用mvc中的angularjs读取文本文件中存在的json数据
i am使用下面的代码
< html>
< head>
< meta name =viewportcontent =width = device-width/>
< title> Angular JS包含< / title>
< br $>
< style>
table,th,td {
border :1px纯灰色;
border-collapse:collapse;
padding:5px;
}
表tr:nth-child(单数){
background-color:#f2f2f2;
}
表tr:nth-child(偶数){
background-color:#ffffff;
}
< / style>
< / head>
<正文>
AngularJS示例应用程序
名称 | Roll No | 百分比 |
---|---|---|
{ {student.Name}} | {{student.RollNo}} | {{student.Percentage}} |
< / body>
< / html>
< script src =〜/ Scripts / angular.min.js>< / script>
< script>
var app = angular.module('myApp',[]);
app.controller('studentController',函数($ scope,$ http){
alert(hh);
$ http.get(data.txt)。成功(函数(响应){$ scope.students = response; });
});
< / script>
和data.txt文件如下桌面
[
{
名称:Mahesh Parashar,
RollNo:101,
百分比:80%
},
{
名称:Dinkar Kad,
RollNo:201,
百分比:70%
},
{
姓名:罗伯特,
RollNo:191,
百分比: 75%
},
{
姓名:朱利安乔,
RollNo:111,
百分比:77%
}
]
范围,
http){
alert(hh);
http.get(data.txt)。success(function(response){
can any please tell me how can i read the json data which is present in text file using angularjs in mvc
i am using the code below
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Angular JS Includes</title>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
AngularJS Sample Application
Name | Roll No | Percentage |
---|---|---|
{{ student.Name }} | {{ student.RollNo }} | {{ student.Percentage }} |
</body>
</html>
<script src="~/Scripts/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('studentController', function ($scope, $http) {
alert("hh");
$http.get("data.txt").success(function (response) { $scope.students=response; });
});
</script>
and the data.txt file as follows on desktop
[
{
"Name" : "Mahesh Parashar",
"RollNo" : 101,
"Percentage" : "80%"
},
{
"Name" : "Dinkar Kad",
"RollNo" : 201,
"Percentage" : "70%"
},
{
"Name" : "Robert",
"RollNo" : 191,
"Percentage" : "75%"
},
{
"Name" : "Julian Joe",
"RollNo" : 111,
"Percentage" : "77%"
}
]
scope,
http) {
alert("hh");
http.get("data.txt").success(function (response) {
这篇关于如何使用mvc中的angularjs读取文本文件中存在的json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!