【问题标题】:Angular 2 error using model in component在组件中使用模型的 Angular 2 错误
【发布时间】:2017-03-05 14:48:04
【问题描述】:

我正在学习 Angular 2,但遇到一个奇怪的错误:

[默认] /home/szabo/PhpstormProjects/recipe-book/src/app/recipes/recipe-list/recipe-item.component.ts:11:2 中的错误 当作为表达式调用时,无法解析属性装饰器的签名。 提供的参数与调用目标的任何签名都不匹配。

这是我的“模型”:

recipe.ts

export class Recipe {
    constructor(public name, public description, public imagePath) {

    }
}

这是我的 RecipeItemComponent

import {Component, OnInit, Input} from '@angular/core';

import { Recipe } from '../recipe';

@Component({
    selector: 'app-recipe-item',
    templateUrl: './recipe-item.component.html',
    styleUrls: ['./recipe-item.component.css']
})
export class RecipeItemComponent implements OnInit {
  @Input recipe: Recipe; //line 11
  recipeId: number;

  constructor() { }

  ngOnInit() {
  }

}

可能是什么问题? 谢谢。

【问题讨论】:

    标签: angular components


    【解决方案1】:

    你的模型不是问题,你在@Input装饰器上缺少()

    @Input() recipe: Recipe;
    

    阅读更多关于Inputhere的信息。

    【讨论】:

    • 您好,感谢您的重播。我是 Angular 的新手,我认为这是一个简单的注释,不一定是一个函数。
    • 您好,感谢您的回答。我相信这是严重的事情,但是 - 我怎么错过了? :) 你是怎么看到的?我是 Angular 2 的新手。
    • @Adrian 错误总是发生,别担心。我建议你完成官方的 Angular 2 教程,它将帮助你理解 Angular 2 的概念,它会帮助你学习语法,这样你就不会再犯这样的愚蠢错误了。 :-) 这是链接:angular.io/docs/ts/latest/tutorial
    猜你喜欢
    • 2017-03-25
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 1970-01-01
    • 2017-02-17
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多