Angular.js - Filter an array in a table based on user input - HTML

1

I want to make a table where td is the name and price of an item. And I want the user to be able to search for an item by its name through input . This is already working. But the table is not showing up as I want, because I enter the array in a single td and I only have one row of items, whereas I want a column. I have this:

ButIwantthenamestoappearinacolumn,notinaline.Mycodeis:

<divclass="container">
    <form class="navbar-form" role="search">
        <div ng-app="myApp" ng-controller="namesCtrl">
            <p>Pesquise um menu</p>
            <p><input type="text" ng-model="test"></p>
    </form>
    <div class="row">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Nome</th>
                        <th>Preço</th>
                    </tr>
                </thead>
                <tbody id="myTable">
                    <tr>
                        <td ng-repeat="x in names | filter:test">{{ x }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

script:

<script>
    angular.module('myApp', []).controller('namesCtrl', function($scope) {
        $scope.names = [
            'Jani',
            'Carl',
            'Margareth',
            'Hege',
            'Joe',
            'Gustav',
            'Birgit',
            'Mary',
            'Kai'
        ];
    });
</script>
    
asked by anonymous 09.06.2016 / 13:33

1 answer

2

Just change this here:

<tr>
    <td ng-repeat="x in names | filter:test">{{ x }}</td>
</tr>

for

<tr ng-repeat="x in names | filter:test">
    <td>{{ x }}</td>
</tr>

When you create ng-repeat in td , you repeat the column and not the tr (line)

    
09.06.2016 / 13:45