1

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;
        });
    }       
});

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Of course I will accept, but I can do it only in 2 minutes. Can you help, how to search only in song_name column for example?
@LevS something like this ng-repeat="data in loaded | filter:{song_name: search}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.