Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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/4/maven/6.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
Javascript 赢得的数据';t角度视图中的载荷_Javascript_Angularjs_Ng View - Fatal编程技术网

Javascript 赢得的数据';t角度视图中的载荷

Javascript 赢得的数据';t角度视图中的载荷,javascript,angularjs,ng-view,Javascript,Angularjs,Ng View,所以我正在学习AngularJS教程,所以我知道这不是完成这些任务的最佳方式,但这是我正在进行的步骤。我试图将数据加载到视图中,但数据不显示。我的ng视图和ng路线工作正常,可以让我到达那里,但一旦我进入patient.html,我只有表格标题,没有任何信息。我错过了什么 这是我的模块 (function() { var app = angular.module('cbApp', ['ngRoute']); app.config(function($routeProvider

所以我正在学习AngularJS教程,所以我知道这不是完成这些任务的最佳方式,但这是我正在进行的步骤。我试图将数据加载到视图中,但数据不显示。我的ng视图和ng路线工作正常,可以让我到达那里,但一旦我进入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 : '/' });
    });

}());
这是我的控制器

(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);
}());
(函数(){
var PatientCtrl=函数($scope,$routeParams){
var roomId=$routeParams.roomId;
$scope.patient=null;
//创建一个搜索房间id的函数
函数init(){
变量长度=$scope.rooms.length;
对于(变量i=0;i
我的看法呢

<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>
房间详细信息
名字
姓
{{pt.first}}
{{pt.last}}

您非常小心地将roomId参数转换为int,然后将其与字符串进行三重相等比较。

我为您完成了插入

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

在这里您可以看到:


{{patient.first}}
{{patient.last}}

加上一些链接和路径

这里是一个代码的工作插件……稍加修改:

angular.module('cbApp',['ngRoute'])。
配置(函数($routeProvider){
//配置您的路由
});
(功能(){
var PatientCtrl=函数($scope,$routeParams){
var roomId=$routeParams.roomId | | 101;
$scope.patients=[];
//创建一个搜索房间id的函数
函数init(){
变量长度=$scope.rooms.length;
对于(变量i=0;i
console中是否有任何错误?如果在for循环后放置console.log($scope.patient),是否在控制台中看到正确的结果?@NishamMahsin nope。没有错误。@Cognitronic是。控制台中显示了正确的对象。@你能做小提琴或弹拨器吗?那么,是因为我试图重复一些没有什么可重复的东西吗?弹拨器中的某些路径不正确。如果($scope.rooms[i].name==roomId){$scope.patient=$scope.rooms[i].patient;break;}为您提供与$routeParams对应的患者。在那之后,你有一个结果,为你的细节
<tr >
        <td>{{ patient.first }}</td>
        <td>{{ patient.last }}</td>
</tr>
    angular.module('cbApp', ['ngRoute']).
    config(function ($routeProvider) {
       //configure your routes
    });
(function() {
    var PatientCtrl = function ($scope, $routeParams) {      

        var roomId = $routeParams.roomId || 101;
        $scope.patients = [];

        //create a function that searches the rooms for id
        function init() {
            var length = $scope.rooms.length;
            for (var i = 0; i < length; i++){
                if (parseInt($scope.rooms[i].name) === parseInt(roomId)) {
                    $scope.patients.push($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();

    }
    //define the controller in angular
    angular.module('cbApp').controller('PatientCtrl', ['$scope', '$routeParams', PatientCtrl]);
}());