Python django angular JS ng-repeat行没有显示

时间:2015-02-14 03:38:01

标签: python django angularjs

我在一个更大的Python Django HTML页面中有一段角度代码 -

{% verbatim %}
<div ng-controller="FwCompController">
    <tbody ng-repeat="fwComp in fwCompList">
        <tr>
             <td>
                 <div class="form-group" >
                     <select name="{{mycomp}}" class="compName">
                         <option value="{{fwComp.value}}" selected="true">{{fwComp.title}}</option>
                         <option value="none">None</option>
                     </select>
                 </div>
             </td>
             <td>
                 <div class="form-group">
                     <input class="form-control" type="text" name={{fwComp.pathName}} placeholder={{fwComp.pathPlaceHolder}}/>
                 </div>
             </td>
                </tr>
    </tbody>
 </div>
{% endverbatim %}

Angular -

var app = angular.module('boombox', []);
app.controller('FwCompController', function ($scope) {
     this.fwCompList = [
       {
           name: "compName1",
           value: "mba",
           title: "UEFI",
           pathName: "compPath1",
           pathPlaceHolder: "/hsc_sw_dvt/rels/mba/7.10.70/evpxe.nic",

       }];
     $scope.mycomp = "compName1";
});

表格行不会在生成的HTML页面中打印出来。为什么?将角度变量指定为HTML属性值是否有效?

1 个答案:

答案 0 :(得分:0)

您应该将fwCompList绑定到$scope

$scope.fwCompList = [
   {
       name: "compName1",
       value: "mba",
       title: "UEFI",
       pathName: "compPath1",
       pathPlaceHolder: "/hsc_sw_dvt/rels/mba/7.10.70/evpxe.nic",

   }];

在旧版代码中,您将fwCompList绑定到this,这是您的控制器FwCompController,而不是$scope。如果您不想更改控制器,则应将HTML更改为

<div ng-controller="FwCompController as fw">
    <tbody ng-repeat="fwComp in fw.fwCompList">