提供的参数不匹配Angular2 MEAN应用中调用目标的任何签名



我不明白这里有什么独特之处。我试图简单地加载一个类的所有对象称为资产,但我一直得到这个错误,当我试图保存结果。

asset.service。ts(24, 23):提供的参数不匹配call target

的任何签名我有以下代码

assets.component.ts

export class AssetsComponent implements OnInit {
  constructor(private assetService: AssetService, private errorService: ErrorService) { }
  assets: Asset[] = [];
  ngOnInit() {
    this.assetService.getAssets()
      .subscribe(
        assets => {
          console.log('assets is', assets);
          this.assets = assets;
          this.assetService.assets = assets;
        },
        error => this.errorService.handleError(error)
      )
  }
}

asset.service.ts

@Injectable()
export class AssetService {
  @Output() asset: Asset;
  assets: Asset[] = [];
  constructor(private _http: Http) { }
  getAssets() {
    return this._http.get('http://localhost:3000/asset')
      .map(response => {
        const data = response.json().obj;
        console.log('getAssets data from response is');
        console.log(data);
        let objs: any[] = [];
        for (let i = 0; i < data.length; i++) {
          console.log('Asset Data here is', data[i]);
          let asset = new Asset(data[i].name, data[i].mimetype, data[i].filename, data[i].local_path, data[i].size);
          objs.push(asset);
        }
        return objs;
      })
      .catch(error => Observable.throw(error.json()));
  }
}

和在我的assets.js路由(在节点使用express)我有

router.get('/', function(req, res, next) {
  Asset.find()
    //.populate('name', 'filename')
    .exec(function(err, docs) {
      if (err) {
        return res.status(404).json({
          title: 'An Error occured',
          error: err
        });
      }
      console.log('node get docs are');
      console.log(docs);
      res.status(200).json({
        asset: 'Success',
        obj: docs
      });
    });
});

我的资产。在Angular2中的模型如下:

export class Asset {
  name: string;
  mimetype: string;
  filename: string;
  local_path: string;
  size: number;
  s3loc: string;
  thumb_local_path: string;
  proxy_local_path: string;
  thumb_s3_path: string;
  proxy_s3_path: string;
... constructor follows...

所以这原来是一些简单的预期,但我没有看到这个答案时搜索。即使我知道当这个特定的getAssets调用运行时,它通常不会在响应中返回所有字段,为了使其工作,所有字段必须在资产服务中创建的对象的新资产部分中占有。

所以上面那行:

let asset = new Asset(data[i].name, data[i].mimetype, data[i].filename, data[i].local_path, data[i].size);

必须是

let asset = new Asset(data[i].name, data[i].mimetype, data[i].filename, data[i].local_path, data[i].size, data[i].s3loc, data[i].thumb_local_path, data[i].proxy_local_path, data[i].thumb_s3_path, data[i].proxy_s3_path);

相关内容

  • 没有找到相关文章

最新更新