标签中显示angularjs信息的问题

时间:2016-04-28 08:23:32

标签: javascript html angularjs

我在 AngularJS 中显示信息的标签存在问题,因为当我使用标记ng-bind时,它运行良好,但是当我使用此标记{{}}时不起作用。

代码:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<!--<script src="static/app/public/js/angular.min.js"></script>-->
<script src="static/app/js/app.js"></script>

<div ng-controller="ClientListCtrl">
    <table>
        <tr>
            <th>ID</th>
            <th>Nom</th>
            <th>Age</th>
            <th>Date</th>
            <th>Actif</th>
        </tr>
        <tr ng-repeat="c in clients">
            <td >{{c.id}}</td>
            <td>{{c.nom}}</td>
            <td>{{c.age}}</td>
            <td>{{c.date_creation|date:'d/M/y'}}</td>
            <td >{{c.actif}}</td>
        </tr>
    </table>
</div>

1 个答案:

答案 0 :(得分:0)

我不知道你遇到了什么问题。我能够使用ng-bind和Angular Expressions {{}}正确运行您的代码。

参阅演示here

请找到以下代码:

<强> HTML:

<div ng-app="app" ng-controller="ClientListCtrl">
  <h3>
With "ng-bind"
</h3>
  <table>
    <tr>
      <th>ID</th>
      <th>Nom</th>
      <th>Age</th>
    </tr>
    <tr ng-repeat="c in clients">
      <td ng-bind="c.id"></td>
      <td ng-bind="c.nom"></td>
      <td ng-bind="c.age"></td>
    </tr>
  </table>
  <br />
  <br />
  <h3>
With "Angular expressions"
</h3>
  <table>
    <tr>
      <th>ID</th>
      <th>Nom</th>
      <th>Age</th>
    </tr>
    <tr ng-repeat="c in clients">
      <td>{{c.id}}</td>
      <td>{{c.nom}}</td>
      <td>{{c.age}}</td>
    </tr>
  </table>
</div>

<强> JS:

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

app.controller('ClientListCtrl', function($scope) {
  $scope.clients = [{
    'id': 1,
    'nom': 'Abc',
    'age': 20
  }, {
    'id': 2,
    'nom': 'Pqr',
    'age': 43
  }, {
    'id': 3,
    'nom': 'Xyz',
    'age': 32
  }, {
    'id': 4,
    'nom': 'Def',
    'age': 67
  }]
});