gpt4 book ai didi

javascript - 数据不会在 Angular View 中加载

转载 作者:行者123 更新时间:2023-11-30 17:04:56 25 4
gpt4 key购买 nike

所以我正在学习 AngularJS 教程,所以我知道这不是完成这些任务的最佳方式,但这是我正在进行的步骤。我正在尝试将数据加载到 View 中,但数据不显示。我的 ng-view 和我的 ng-route 工作正常,可以让我到达那里,但是一旦我在 patient.html 上,我只有表格标题,没有任何信息。我错过了什么?

这是我的模块

(function() {

var app = angular.module('cbApp', ['ngRoute']);

app.config(function($routeProvider){
$routeProvider
.when('/',{
controller : 'MainCtrl',
templateUrl : 'views/main.html'
})
.when('/patient/:roomId', {
controller : 'PatientCtrl',
templateUrl : 'views/patient.html'
})
.otherwise({ redirectTo : '/' });
});

}());

这是我的 Controller

(function() {
var PatientCtrl = function ($scope, $routeParams) {

var roomId = $routeParams.roomId;
$scope.patient = null;

//create a function that searches the rooms for id
function init() {
var length = $scope.rooms.length;
for (var i = 0; i < length; i++){
if ($scope.rooms[i].name === parseInt(roomId)) {
$scope.patient = $scope.rooms[i].patient;
break;
}
}
}
$scope.rooms = [
{ id : 101, name : "101", patient : { id : 1, last: "Ratcliff", first : "Daniel"} },
{ id : 102, name : "102", patient : { id : 2, last: "Gibson", first : "Mel"} },
{ id : 103, name : "103", patient : { id : 3, last: "Fey", first : "Tina"} }
];
init();

}
//handle DI to avoid minification errors
PatientCtrl.$inject = ['$scope', '$routeParams'];
//define the controller in angular
angular.module('cbApp').controller('PatientCtrl', PatientCtrl);
}());

我的看法

<h2>Room Details</h2>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="pt in patient">
<td>{{ pt.first }}</td>
<td>{{ pt.last }}</td>
</tr>
</table>

最佳答案

我为你完成了你的 plunker。

但不确定这是否是您想要实现的。

在这里你可以看到它:

plunker

<tr >
<td>{{ patient.first }}</td>
<td>{{ patient.last }}</td>
</tr>

加上一些链接和路径

关于javascript - 数据不会在 Angular View 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28202047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com