简体   繁体   English

角度从代码中删除@Input装饰器

[英]Angular removing an @Input decorator from code

I'm writing code for a class on Angular, and cannot understand why pulling the @Input decorator from my component is causing the entire application not to load. 我正在为Angular上的类编写代码,无法理解为什么从组件中拉出@Input装饰器会导致整个应用程序无法加载。

 import { Component, OnInit, Input } from '@angular/core'; import { Dish } from '../shared/dish'; import { DishService } from '../services/dish.service'; import { Params, ActivatedRoute } from '@angular/router'; import { Location } from '@angular/common'; @Component({ selector: 'app-dishdetail', templateUrl: './dishdetail.component.html', styleUrls: ['./dishdetail.component.scss'] }) export class DishdetailComponent implements OnInit { @Input() dish: Dish; constructor(private dishservice: DishService, private route: ActivatedRoute, private location: Location) { } ngOnInit() { let id = +this.route.snapshot.params['id']; this.dish = this.dishservice.getDish(id); } } 

The input component isn't used anywhere else in the application, and as far as I can tell its not that strongly related even to this component, so can anyone explain why it is that when I remove that decorator, it breaks my program? 输入组件未在应用程序中的其他任何地方使用,据我所知甚至与该组件没有密切关系,所以谁能解释为什么当我删除该装饰器时,它破坏了我的程序?

If you would just open your browser's console, you would see the big fat error message, saying something like 如果您只是打开浏览器的控制台,则会看到一条大错误消息,内容如下:

Can't bind to 'dish' since it isn't a known property of 'app-dishdetail' 无法绑定到“ dish”,因为它不是“ app-dishdetail”的已知属性

Additionally, the error message tells you exactly where you try to bind to dish . 此外,错误消息还告诉您确切的位置,您尝试绑定到dish

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM