简体   繁体   English

为什么我的角度列表不显示?

[英]Why wont my angular List show up?

I am working on an Angular project using, Web API and entity framework code first. 我首先使用Web API和实体框架代码来开发Angular项目。 I have a view that has a table on the bottom. 我有一个视图,该视图的底部。 When the view is loaded it calls back to the database to load the list. 加载视图时,它会回调数据库以加载列表。 I have set break points at various locations to make sure that I am getting back the right data from the Data base and I trace it back into the angular controller. 我在各个位置都设置了断点,以确保从数据库中检索到正确的数据并将其追溯到角度控制器中。 In the controller the data is there but it then goes off into the ether. 在控制器中,数据在那里,但随后进入以太网。 I can look at the response headers and it is there. 我可以看一下响应头,它在那里。 I am kind of at a loss. 我有点茫然。 I put in some json serialization in WebApiConfig To deal with the camel/Pascal case issue. 我在WebApiConfig中放入了一些json序列化来处理骆驼/帕斯卡的案例问题。 Here is my view code: 这是我的查看代码:

    <div class=" nav">
        <div class="span12">
          <h3> Work with Dictionaries </h3>
           <ul class="navbar-nav">
             <li><a ui-sref-active="active" style="margin-right: 25px;" ui-sref="injuriesDict">Injuries Dictionary</a></li>
            <li><a ui-sref-active="active" ui-sref="excercisesDict">Excercise Dictionary</a></li>
         </ul>
         </div>
         </div>

<h3>Patient Entry Form</h3>
<ul class="navbar-nav">
    <li><a ui-sref-active="active" ui-sref="patientEntry">Patient Entry</a></li>    
</ul>

       <div class="container span12">
        <div class="row">
        <h1>Patient Search</h1>
        <form class="form-search horizontal-form" method="POST">
            <label for="lastName">LastName</label>
            <input type="text" class="input-medium" style="margin-bottom: 10px;" id="lastName" name="name">
            <br>
            <label for="ssn">SSN</label>
            <input type="text" class="input-medium" style="margin-left: 40px; margin-bottom: 10px" id="ssn" name="ssn">
            <br>
            <label for="mrn">MRN</label>
            <input type="text" class="input-medium" style="margin-left: 32px; margin-bottom: 20px;" id="mrn" name="mrn">
            <br>
            <button type="button" class="btn btn-default" ng-click="vm.patientSearch();">Search</button>
        </form>
    </div>
    </div>

    <div class="container">
    <div class="row">
        <h2>Patient Results</h2>
        <div ng-controller=" patientSearch as vm">
            <table style="border: 1px;" class="span8">
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>MRN #</th>
                    <th>SSN</th>
                    <th>Injury Type</th>
                    <th>Injury Date</th>
                </tr>
                <tr>
                    <th>{{vm.firstName}}</th>
                    <th>{{vm.lastName}}</th>
                    <th>{{vm.mrn}}</th>
                    <th>{{vm.ssn}}</th>
                    <th>{{vm.injuryType}}</th>
                    <th>{{vm.injuryDate | date}}</th>
                </tr>
            </table>
        </div> 
    </div>
</div>

Here is my controller code 这是我的控制器代码

(function() {
    'use strict';
     angular.module('app')
      .controller('patientSearch', ["patientResource", patientSearch]);


    function patientSearch(patientResouce) {
       var vm = this;
        patientResouce.query(function(data) {
        vm.patients = data;

     });
   }
 }());

 I just don't see why it is not loading the table, does anybody see anything drastically wrong with my code?

You probably want something like this: 您可能想要这样的东西:

        <table style="border: 1px;" class="span8">
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>MRN #</th>
                <th>SSN</th>
                <th>Injury Type</th>
                <th>Injury Date</th>
            </tr>
            <tr ng-repeat="patient in patients">
                <th>{{patient.firstName}}</th>
                <th>{{patient.lastName}}</th>
                <th>{{patient.mrn}}</th>
                <th>{{patient.ssn}}</th>
                <th>{{patient.injuryType}}</th>
                <th>{{patient.injuryDate | date}}</th>
            </tr>
        </table>

That is assuming you want your patient list as table contents, one row per patient record. 假设您希望将患者列表作为表格内容,每条患者记录一行。

You need to use the controllerAs syntax (vm.patients) : 您需要使用controllerAs语法(vm。Patients):

<tr ng-repeat="patient in vm.patients">
                <th>{{patient.firstName}}</th>
                <th>{{patient.lastName}}</th>
                <th>{{patient.mrn}}</th>
                <th>{{patient.ssn}}</th>
                <th>{{patient.injuryType}}</th>
                <th>{{patient.injuryDate | date}}</th>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM