Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 即使组件中存在属性,角度测试错误_Javascript_Angular - Fatal编程技术网

Javascript 即使组件中存在属性,角度测试错误

Javascript 即使组件中存在属性,角度测试错误,javascript,angular,Javascript,Angular,运行ng测试时,我遇到以下错误: Can't bind to 'foobar' since it isn't a known property of 'app-my-item'. 1. If 'app-my-item' is an Angular component and it has 'foobar' input, then verify that it is part of this module. 2. If 'app-my-item' is a Web Component then

运行
ng测试时,我遇到以下错误:

Can't bind to 'foobar' since it isn't a known property of 'app-my-item'.

1. If 'app-my-item' is an Angular component and it has 'foobar' input, then verify that it is part of this module.
2. If 'app-my-item' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
组件:

import { Component, Input, OnInit, Renderer, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core';

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

export class MyItemComponent implements OnInit, OnChanges {

  @Input() video;
  @Input() foobar = <string> '';
  buttonClass = 'green';

  // Code....

  ngOnChanges({ foobar: { currentValue } }: SimpleChanges): void {
    if (currentValue) {
      this.buttonClass = (
        currentValue === this.video.key ? 'blue' : 'green'
      );
    }
  }

  // Code....

}
  <app-my-item
      //Code ....
      [foobar]="foobar"
      //Code ....
  >
  </app-my-item>
import{Component,Input,OnInit,Renderer,EventEmitter,Output,OnChanges,SimpleChanges}来自'@angular/core';
@组成部分({
选择器:“应用程序我的项目”,
templateUrl:'./app item.component.html',
样式URL:['./app item.component.scss'],
})
导出类MyItemComponent实现OnInit、OnChanges{
@输入()视频;
@输入()foobar='';
buttonClass='绿色';
//代码。。。。
ngOnChanges({foobar:{currentValue}}}:SimpleChanges):void{
if(当前值){
this.buttonClass=(
currentValue==this.video.key?'blue':'green'
);
}
}
//代码。。。。
}
查看:

import { Component, Input, OnInit, Renderer, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core';

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

export class MyItemComponent implements OnInit, OnChanges {

  @Input() video;
  @Input() foobar = <string> '';
  buttonClass = 'green';

  // Code....

  ngOnChanges({ foobar: { currentValue } }: SimpleChanges): void {
    if (currentValue) {
      this.buttonClass = (
        currentValue === this.video.key ? 'blue' : 'green'
      );
    }
  }

  // Code....

}
  <app-my-item
      //Code ....
      [foobar]="foobar"
      //Code ....
  >
  </app-my-item>


我不明白为什么会出现错误,因为
foobar
实际上是在组件中定义为输入的。如何修复此错误?

是否有可能对空字符串的默认赋值使其失去跟踪?@MotKohn刚刚更改
@Input()foobar=''
@Input()foobar和同样的错误:(你能添加你的模块文件吗?你在测试哪个组件?
应用程序项
或其他组件?