Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html MVC模型列表到AngularJs_Html_Asp.net Mvc_Angularjs - Fatal编程技术网

Html MVC模型列表到AngularJs

Html 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); })

我有一个模型,有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);
});
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然后它就可以工作了