简体   繁体   English

无法绑定到“测试”,因为它不是“输入”的已知属性

[英]Can't bind to 'testing' since it isn't a known property of 'input'

I have been trying to learn how to use Angular's @Input decorator and for some reason I cannot figure out what is wrong. 我一直在尝试学习如何使用Angular的@Input装饰器,由于某种原因,我无法弄清楚出了什么问题。

I have properly imported the FormsModule in my app component but I keep getting the above error. 我已经在我的应用程序组件中正确导入了FormsModule,但是我仍然收到上述错误。 Can someone please help? 有人可以帮忙吗?

Do I have a typo somewhere that I just cannot see? 我在看不见的地方有错字吗?

app.module.ts app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { RecipeComponent } from './components/recipe/recipe.component';

@NgModule({
  declarations: [
    AppComponent,
    RecipeComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

component.ts component.ts

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

@Component({
  selector: 'app-recipe',
  templateUrl: './recipe.component.html',
  styleUrls: ['./recipe.component.css']
})

export class RecipeComponent implements OnInit {
  @Input() testing;

component.html component.html

  <ul class="ingredient-list">
    <li *ngFor="let list of lists; let i = index;"><input type="checkbox" [testing]="list.checked" (click)="verifyAllChecked(i)" >{{list.quantity}}<br>{{list.item}}</li>
  </ul>
{{testing}}

You need to put this code in your component.html 您需要将此代码放在您的component.html中

<input type="checkbox" (click)="verifyAllChecked(i)" >

and then add your component tag to the app component like: 然后将您的组件标签添加到应用程序组件,例如:

<app-recipe [testing]="list.checked" ></app-recipe>

Input tag does not have testing property binding that's why it throws below error 输入代码没有测试属性绑定,这就是为什么它抛出以下错误

Can't bind to 'testing' since it isn't a known property of 'input' 无法绑定到“测试”,因为它不是“输入”的已知属性

暂无
暂无

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

相关问题 无法绑定到&#39;mdDatepicker&#39;,因为它不是&#39;input&#39;的已知属性 - Can't bind to 'mdDatepicker' since it isn't a known property of 'input' 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“shouldLabelFloat”,因为它不是“input”的已知属性 - Can't bind to 'shouldLabelFloat' since it isn't a known property of 'input' 无法绑定到“ngValue”,因为它不是“input”的已知属性 - Can't bind to 'ngValue' since it isn't a known property of 'input' “无法绑定到‘ngModel’,因为它不是‘输入’的已知属性” - “Can't bind to 'ngModel' since it isn't a known property of 'input' ” 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’ 无法绑定到“上载器”,因为它不是“输入”的已知属性 - Can't bind to 'uploader' since it isn't a known property of 'input' 无法绑定到“typeahead”,因为它不是“input”的已知属性 - Can't bind to 'typeahead' since it isn't a known property of 'input' 无法绑定到“matDatepicker”,因为它不是“输入”的已知属性 - Can't bind to 'matDatepicker' since it isn't a known property of 'input' angular2 测试:无法绑定到“ngModel”,因为它不是“input”的已知属性 - angular2 testing: Can't bind to 'ngModel' since it isn't a known property of 'input'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM