MEAN堆栈问题

时间:2017-11-12 14:29:57

标签: node.js angular

我对堆栈MEAN比较新,还在学习它。

我收到一个错误,我没看到错误在哪里。这来自Angular中的from。 这是我的错误的输出:

  

输入'()=>任何'不能分配'任何[]'。类型'()=>中缺少属性'push'任何”。

    import { ApplicationService } from './../../services/applicationService/application.service';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: "cc-search",
  templateUrl: "./search.component.html",
  styleUrls: ["./search.component.css"]
})
export class SearchComponent implements OnInit {
  applications = [];
  constructor(private applicationService: ApplicationService) {}

  ngOnInit() {}
  searchApplications(searchData) {
    this.applicationService
      .searchApplication(searchData)
      .subscribe(
        data => this.applications = data,
        error => console.error(error)
      );
  }
}

从服务器端: 我不知道它是什么样的错误,可能是我的路线不对,因为我无法得到信息。

const getAllApplications = () => {
    return [...addedApplications, ...initialApplications];
};

api.get('search/:term/:place?', (req, res) => {
    const term = req.params.term.toLowerCase().trim();
    let place = req.params.place;
    let applications = getAllApplications().filter(j => (j.description.toLowerCase().includes(term) || j.title.toLowerCase().includes(term)));
    console.log('test');
    if (place) {
        place = place.toLowerCase().trim();
        applications = applications.filter(j => (j.city.toLowerCase().includes(place)));
    }
    res.json({ success: true, applications: applications });
});

提前致谢

1 个答案:

答案 0 :(得分:1)

您没有声明订阅结果的类型。您应该明确指定结果的类型:

this.applicationService
    .searchApplication(searchData)
    .subscribe(
        (data: Application[]) => this.applications = data,
        error => console.error(error)
        );  

我认为您的模型是Application