无法制作动态两列表

时间:2016-10-22 00:22:25

标签: javascript angularjs

我希望有一个表格,其中包含从两个数组的对象动态加载的标题和数据。不幸的是,这些行不会显示。

http://jsfiddle.net/x7ur9u07/4/

<div ng-controller="MyCtrl">
  <table>
    <thead>
      <tr>
        <th>Input</th>
        <th>Output</th>
      <tr>
    </thead>
    <tbody>
      <tr ng-repeat="inout in inoutContainer track by $index">
        <td>{{ inout.input_vector[$index] }}</td>
        <td>{{ inout.output_vector[$index] }}</td>
      </tr>
      <tr>
        <td>
          Foo
        </td>
        <td>
          Bar
        </td>
      </tr>
    </tbody>
  </table>
</div>

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

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
    window.alert('hello');
        $scope.inoutContainer = {input_vector: ["0.0","0.0"], output_vector: ["0.0","0.0"]};
    $scope.name = 'Superhero';
}

1 个答案:

答案 0 :(得分:1)

我设法找到一种方法让它工作 - 你有一些语法错误,angularJS不理解

http://jsfiddle.net/x71jm9r8/

基本上我简化了angularJS代码

  • 然后将ng-app指令添加到容器div

  • 删除了track by $index指令的ng-repeat部分,

  • 最后添加了myApp.controller()声明。