Lev
Lev

Reputation: 101

AngularJS search doesn't work

I have a MySQL database and table in it. I take data from it using Node JS. My HTML code contains input search and a table that has data from search results. I use AngularJS for searching.

The problem is that search doesn't work. I have the whole table instead of some results.

Part of HTML code:

<div class="search">
  <form action="" method="post" class="searchform" >
    <input type="search" name="" placeholder="Поиск" class="inputsearchform" ng-model="search"/>
    <input type="submit" name="" value="" class="submitsearchform" />
  </form>
</div>
<div class="songlist" ng-app='test_table' ng-controller='main_control'>
  <table id="songlistTableR">   
    <tr><th>Name</th><th>Link</th></tr>    
    <tr ng-repeat="data in loaded | filter:search">
      <td><i class="fa fa-plus"></i>{{data.song_name}}</td>
      <td><a href="{{data.link}}" target='_blank'>Youtube</a></td>     
    </tr>
  </table>      
</div>

JS script:

var app = angular.module('test_table', []);
app.controller('main_control',function($scope, $http){
    load();
    function load(){
        $http.get("http://localhost:7001/load").success(function(data){
            $scope.loaded=data;
        });
    }       
});

Upvotes: 1

Views: 164

Answers (1)

Tmb
Tmb

Reputation: 470

All your angular html code need to be nested in the ng-app attribute, so your <div class="search"> is never parsed by Angular, including your ng-model definition. You should edit your code into something like:

<div class="songlist" ng-app='test_table' ng-controller='main_control'>
  <div class="search">
    <form action="" method="post" class="searchform" >
      <input type="search" name="" placeholder="Поиск" class="inputsearchform" ng-model="search"/>
      <input type="submit" name="" value="" class="submitsearchform" />
    </form>
  </div>
  <table id="songlistTableR">   
    <tr><th>Name</th><th>Link</th></tr>    
    <tr ng-repeat="data in loaded | filter:search">
      <td><i class="fa fa-plus"></i>{{data.song_name}}</td>
      <td><a href="{{data.link}}" target='_blank'>Youtube</a></td>     
    </tr>
  </table>      
</div>

Upvotes: 2

Related Questions