twitter-bootstrap – 具有角度的可点击引导行

前端之家收集整理的这篇文章主要介绍了twitter-bootstrap – 具有角度的可点击引导行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一张桌子,风格有自举.此表的内容使用Angular.js填充.如何使行可点击,以便调用范围内的函数

以下代码对我无效(ng点击部分):

表:

<table class="table table-hover">
        <thead>
            <tr>
                <th>Name</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="ingredient in ingredients" ng-click="setSelected({{$index}});">
                <td>{{ ingredient.name }}</td>
                <td>{{ ingredient.status }}</td>
            </tr>
        </tbody>
    </table>

控制器:

$scope.setSelected = function(index) {
    $scope.selected = $scope.ingredients[index];
    console.log($scope.selected);
};

解决方法

建议和 fiddle
<tr ng-repeat="ingredient in ingredients" ng-click="setSelected();">
    <td>{{ ingredient.name }}</td>
    <td>{{ ingredient.status }}</td>
</tr>

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

function MyCtrl($scope) {

    $scope.ingredients = [
        {'name': 'potato'},{'name': 'tomato'}
    ];

    $scope.setSelected = function() {
        $scope.selected = this.ingredient;
        console.log($scope.selected);
    };

}
</script>

猜你在找的Bootstrap相关文章