Search Data with my sql node js and Angular 6

node js

Node js code


app.get('/search', function (req, res) {
  console.log(req.query.key +"aman")
  connection.query('SELECT * from blog where blog_name like"%'+req.query.key+'%"',
    function (err, rows, fields) {
      if (err) throw err;
      var data = [];
      for (i = 0; i < rows.length; i++) {
console.log(rows[i].blog_name )
console.log(rows[i].blog_id )
data.push(rows[i].blog_name );
      }
      res.end(JSON.stringify(data));
    });
});

-----------------------------------------------------------------

  serachData(data){
    return this.http.get('http://localhost:8000/search'+ '?key=' + data )
  }

  globalSearchData(searchInputValue) {
    let data = {
      "blog_name": searchInputValue
    }
    this.dataService.serachData(searchInputValue).subscribe(
      data => this.globalSearchDataResponse(data),
      error => this.globalSearchDataResponse(error)
    )
  }

  globalSearchDataResponse(data) {
    this.searchData = data;
    console.log(this.searchData)
}

-------------------
  <div class="search_container">
    <form>
      <input type="text"  (input)="eventHandler($event)" id="search_bar" autocomplete="off" placeholder="Search">
      <span class="search_bar_icon">
        <i class="material-icons">search </i>
      </span>

    </form>
    <div class="serach_wrapper">
      <li *ngFor="let item of searchData" >
        {{item}}
      </li>
    </div>
  </div>

Comments

Popular Posts