Html MVC模型列表到AngularJs
我有一个模型,有studentID、firstName、LastName、PhotoURL和一个列表,我试着像这样将模型绑定到angularJsHtml MVC模型列表到AngularJs,html,asp.net-mvc,angularjs,Html,Asp.net Mvc,Angularjs,我有一个模型,有studentID、firstName、LastName、PhotoURL和一个列表,我试着像这样将模型绑定到angularJs var app = angular.module('StudentApp', []); app.controller('StudentCtrl', function ($scope) { $scope.model = @Html.Raw(Json.Encode(Model)); console.log($scope.model); })
var app = angular.module('StudentApp', []);
app.controller('StudentCtrl', function ($scope) {
$scope.model = @Html.Raw(Json.Encode(Model));
console.log($scope.model);
});
Object {StudentID: 0, FirstName: null, LastName: null, PhotoURL: null, _StudentList: Array[5]}
FirstName: null LastName: null PhotoURL: null StudentID: 0 _StudentList:Array[5]
0: Object
FirstName: "John"
LastName: "Doe"
PhotoURL: "phone-wallpaper-1920x1200.jpg"
StudentID: 5
_StudentList: null__proto__:
1: Object
FirstName: "Ahri"
LastName: "Fox"
PhotoURL: "ahri-wallpaper-1920x1200.jpg"
StudentID: 6
_StudentList: null__proto__:
Object2:
Object3:
Object4:
<table class="table" ng-app="StudentApp">
<tbody ng-controller="StudentCtrl">
<tr>
<th>Key</th>
<th>First Name</th>
<th>Last Name</th>
<th>Profile picture</th>
<th>Options</th>
</tr>
<tr ng-repeat="student in $scope.model._StudentList">
<td></td>
<td>{{student.FirstName}}</td>
<td>{{student.LastName}}</td>
</tr>
}
</tbody>
当我使用console.log时
它是这样向我展示的
var app = angular.module('StudentApp', []);
app.controller('StudentCtrl', function ($scope) {
$scope.model = @Html.Raw(Json.Encode(Model));
console.log($scope.model);
});
Object {StudentID: 0, FirstName: null, LastName: null, PhotoURL: null, _StudentList: Array[5]}
FirstName: null LastName: null PhotoURL: null StudentID: 0 _StudentList:Array[5]
0: Object
FirstName: "John"
LastName: "Doe"
PhotoURL: "phone-wallpaper-1920x1200.jpg"
StudentID: 5
_StudentList: null__proto__:
1: Object
FirstName: "Ahri"
LastName: "Fox"
PhotoURL: "ahri-wallpaper-1920x1200.jpg"
StudentID: 6
_StudentList: null__proto__:
Object2:
Object3:
Object4:
<table class="table" ng-app="StudentApp">
<tbody ng-controller="StudentCtrl">
<tr>
<th>Key</th>
<th>First Name</th>
<th>Last Name</th>
<th>Profile picture</th>
<th>Options</th>
</tr>
<tr ng-repeat="student in $scope.model._StudentList">
<td></td>
<td>{{student.FirstName}}</td>
<td>{{student.LastName}}</td>
</tr>
}
</tbody>
这意味着我得到了五个学生的数据,现在我想用ng repeat打印这五个学生的数据
我试过这样做
var app = angular.module('StudentApp', []);
app.controller('StudentCtrl', function ($scope) {
$scope.model = @Html.Raw(Json.Encode(Model));
console.log($scope.model);
});
Object {StudentID: 0, FirstName: null, LastName: null, PhotoURL: null, _StudentList: Array[5]}
FirstName: null LastName: null PhotoURL: null StudentID: 0 _StudentList:Array[5]
0: Object
FirstName: "John"
LastName: "Doe"
PhotoURL: "phone-wallpaper-1920x1200.jpg"
StudentID: 5
_StudentList: null__proto__:
1: Object
FirstName: "Ahri"
LastName: "Fox"
PhotoURL: "ahri-wallpaper-1920x1200.jpg"
StudentID: 6
_StudentList: null__proto__:
Object2:
Object3:
Object4:
<table class="table" ng-app="StudentApp">
<tbody ng-controller="StudentCtrl">
<tr>
<th>Key</th>
<th>First Name</th>
<th>Last Name</th>
<th>Profile picture</th>
<th>Options</th>
</tr>
<tr ng-repeat="student in $scope.model._StudentList">
<td></td>
<td>{{student.FirstName}}</td>
<td>{{student.LastName}}</td>
</tr>
}
</tbody>
它正在打印John Doe您不应该在ng repeat中使用$scope,只需将其制作为模型即可。_StudentList然后它就可以工作了