Angular - I can not display table data

0

I do not understand why it does not display the table data, it's identical to the page you were using to study.

Code:

<!DOCTYPE html>
<html>
<script src="/lib/angular-1.4.8.min.js"></script>
<body>

<div class="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 ng-repeat="x in names | filter:test">
                        <td>{{ x }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    angular.module('myApp', []).controller('namesCtrl', function($scope) {
        $scope.names = [
            'Jani',
            'Carl',
            'Margareth',
            'Hege',
            'Joe',
            'Gustav',
            'Birgit',
            'Mary',
            'Kai'
        ];
    });
</script>

</body>
</html>

Result:

    
asked by anonymous 20.10.2017 / 12:37

1 answer

4

There's nothing wrong with the code itself. Probably the script location of AngularJS is not /lib/angular-1.4.8.min.js .

HTML is a bit strange, but that does not stop the application from working.

It has an opening of div remaining within form . The HTML should look more like the one below.

See the code working using a CDN.

angular.module('myApp', []).controller('namesCtrl', function($scope) {
        $scope.names = [
            'Jani',
            'Carl',
            'Margareth',
            'Hege',
            'Joe',
            'Gustav',
            'Birgit',
            'Mary',
            'Kai'
        ];
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divclass="container" ng-app="myApp" ng-controller="namesCtrl">
    <form class="navbar-form" role="search">
            <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 ng-repeat="x in names | filter:test">
                        <td>{{ x }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
    
20.10.2017 / 12:56