为什么ng-repeat不能用于表格?

时间:2016-07-01 07:05:53

标签: javascript angularjs

ng-repeat不使用表,在仅输出标题部分显示?因为我认为我所做的绑定完全没问题,但我缺少哪些东西? 当我尝试在Stackoverflow中运行时,它运行正常。

我正在使用ADOBE Brackets.Wan括号中的错误? 请为angularjs推荐最好的IDE? 任何人都可以帮我解决我做错的地方吗?



var myApp=angular.module("myApp",[]);
var mycontroller=function($scope)
{
var employees=[
    {Name:'Sahil',dateOfBirth:new Date(),gender:"Male",salary: 400000},
    {Name:'Shaloni',dateOfBirth:new Date(),gender:"Female",salary: 100000},
    {Name:'Nitish',dateOfBirth:new Date(),gender:"Male",salary: 300000},
    {Name:'Diksha',dateOfBirth:new Date(),gender:"Female",salary: 600000},
    {Name:'Tarun',dateOfBirth:new Date(),gender:"Male",salary: 900000}
]
$scope.emp=employees;
};
myApp.controller('myController',mycontroller);

<HTML ng-app="myApp">
<Head>
<title></title>
<script src="https://code.angularjs.org/1.5.0-rc.0/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src="day4.js"></script>
    <link href="Style.css" rel="stylesheet"/> 
</Head>

<body>
<div ng-controller="myController">
<table>
<thead>
<th>Name</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Salary</th>
<th>Salary in Dollors</th>
</thead>
<tbody>
<tr ng-repeat="employee in emp">
    <td>{{employee.Name}}</td>    
    <td>{{employee.dateOfBirth}}</td>
    <td>{{employee.gender}}</td>
    <td>{{employee.salary}}</td>
    <td></td>
</tr>
</tbody>
</table>

</div>
</body>
</HTML>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

请找到您的解决方案https://plnkr.co/edit/hFIfPlTcP8VLVE72coth

您的代码中存在问题:   var mycontroller = function($ scope) 和myApp.controller(&#39; myController&#39;,mycontroller);

mycontroller变量未被调用。 put Alert();在那个街区,看看。

对于编辑器,您可以使用SUBLIME编辑器,Visual Studio代码,Intellisense for angular2

&#13;
&#13;
var myApp=angular.module("myApp",[]);
var mycontroller=function($scope)
{
var employees=[
    {Name:'Sahil',dateOfBirth:new Date(),gender:"Male",salary: 400000},
    {Name:'Shaloni',dateOfBirth:new Date(),gender:"Female",salary: 100000},
    {Name:'Nitish',dateOfBirth:new Date(),gender:"Male",salary: 300000},
    {Name:'Diksha',dateOfBirth:new Date(),gender:"Female",salary: 600000},
    {Name:'Tarun',dateOfBirth:new Date(),gender:"Male",salary: 900000}
]
$scope.emp=employees;
};
myApp.controller('myController',mycontroller);
&#13;
<HTML ng-app="myApp">
<Head>
<title></title>
<script src="https://code.angularjs.org/1.5.0-rc.0/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    <script src="day4.js"></script>
    <link href="Style.css" rel="stylesheet"/> 
</Head>

<body>
<div ng-controller="myController">
<table>
<thead>
<th>Name</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Salary</th>
<th>Salary in Dollors</th>
</thead>
<tbody>
<tr ng-repeat="employee in emp">
    <td>{{employee.Name}}</td>    
    <td>{{employee.dateOfBirth}}</td>
    <td>{{employee.gender}}</td>
    <td>{{employee.salary}}</td>
    <td></td>
</tr>
</tbody>
</table>

</div>
</body>
</HTML>
&#13;
&#13;
&#13;