【问题标题】:Angular Template directive for ng-repeat and ng-classng-repeat 和 ng-class 的 Angular 模板指令
【发布时间】:2015-02-18 19:34:18
【问题描述】:

我正在尝试在元素模板中获取代码:

rent.html

<td>{{ rent.id }}</td>
<td>{{ rent.auto }}</td>
<td>{{ rent.person }}</td>
<td>{{ rent.title }}</td>
<td>{{ rent.start }}</td>
<td>{{ rent.end }}</td>
<td><a ng-href="#" ng-click="acceptRent(rent.id)"><img src="bundles/chriskfzbuchung/images/accept.png" width="15" ng-hide="rent.buchungsStatus == 1"></a></td>
<td><a ng-href="#" ng-click="declineRent(rent.id)"><img src="bundles/chriskfzbuchung/images/decline.png" width="15" ng-hide="rent.buchungsStatus == 2"></a></td>

controller.js

 kfzModule.directive("kfzRent", function(){
        return {
            restrict: 'E',
            templateUrl: '/kfz-buchung/rent.html'
        };
    });

overview.html

<tr kfz-rent ng-repeat="rent in rents" ng-class="{'success' : rent.buchungsStatus == 1, 'danger' : rent.buchungsStatus == 2}">
                </tr>

我不知道如何处理overview.html中的其余部分。

我终于想要一个&lt;kfz-rent&gt;&lt;/kfz-rent&gt;

谢谢!

【问题讨论】:

  • 我有点困惑你想要什么?
  • 我不想在overview.html中有ng-repeat和ng-class指令,overview.html应该只有
  • 把overview.html中除了kfz-rent属性之外的所有内容放到rent.html中
  • 不适用于 元素(我在rent.html 中使用了 )
  • 我也没有 javascript 错误

标签: javascript html angularjs templates directive


【解决方案1】:

这应该有效:

 <kfz-rent ng-repeat="rent in rents" ng-class="{'success' : rent.buchungsStatus == 1, 'danger' : rent.buchungsStatus == 2}">
    <td>{{ rent.id }}</td>
    <td>{{ rent.auto }}</td>
    <td>{{ rent.person }}</td>
    <td>{{ rent.title }}</td>
    <td>{{ rent.start }}</td>
    <td>{{ rent.end }}</td>
    <td><a ng-href="#" ng-click="acceptRent(rent.id)"><img src="bundles/chriskfzbuchung/images/accept.png" width="15" ng-hide="rent.buchungsStatus == 1"></a></td>
    <td><a ng-href="#" ng-click="declineRent(rent.id)"><img src="bundles/chriskfzbuchung/images/decline.png" width="15" ng-hide="rent.buchungsStatus == 2"></a></td>
</kfz-rent>

ng-repeat 的代码似乎没问题。但是你必须在你的控制器中创建数组:

$scope.rents = []; 

别忘了给你的控制器起一个别名

kfzModule.directive("kfzRent", function(){
    return {
        restrict: 'E',
        templateUrl: '/kfz-buchung/rent.html'
    };
   },
   controllerAs: 'rentController'
 };
});

干杯,

瓦伦丁

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签