Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Angular 角度误差NG8002:Can';t绑定到';ngStyle';因为它不是';t'的已知属性;分区';_Angular - Fatal编程技术网

Angular 角度误差NG8002:Can';t绑定到';ngStyle';因为它不是';t'的已知属性;分区';

Angular 角度误差NG8002:Can';t绑定到';ngStyle';因为它不是';t'的已知属性;分区';,angular,Angular,在Angular-11中,我有以下代码: 密码-meter.component.ts: import {Component, Input, OnInit} from '@angular/core'; @Component({ selector: 'app-password-meter', templateUrl: './password-meter.component.html', styleUrls: ['./password-meter.component.css'] }) e

在Angular-11中,我有以下代码:

密码-meter.component.ts:

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

@Component({
  selector: 'app-password-meter',
  templateUrl: './password-meter.component.html',
  styleUrls: ['./password-meter.component.css']
})
export class PasswordMeterComponent implements OnInit {
  @Input() passwordString: string;

  constructor() {
  }

  ngOnInit(): void {
  }

  get passwordStrength() {
    const password = this.passwordString || '';
    let score = Math.min(4, password.length / 2);
    if (/[a-z]/.test(password)) {
      score += 1;
    }

    if (/[a-z](.)*[a-z]/.test(password)) {
      score += 3;
    }
    if (/[A-Z]/.test(password)) {
      score += 1;
    }
    if (/[A-Z](.)*[A-Z]/.test(password)) {
      score += 2;
    }

    if (/\W|_/.test(password)) {
      score += 2;
    }

    if (/(\W|_)(.)*(\W|_)/.test(password)) {
      score += 3;
    }
    if (/[0-9]/.test(password)) {
      score += 2;
    }

    if (/[0-9](.)*[0-9]/.test(password)) {
      score += 2;
    }

    return (score / 20) * 100;
  }

  get colorString() {
    const hue = ((this.passwordStrength / 100) * 120).toString(10);
    return ['hsl(', hue, ',100%,50%)'].join('');
  } 
}
password-meter.component.html:

新密码强度
{{passwordStrength}数字:'2.0-0'}}

@NgModule
中声明了
密码表组件的
模块中,您需要确保该组件包含在
导入中

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { PasswordMeterComponent } from './path/to/password-meter.component.ts';

@NgModule({
  declarations: [PasswordMeterComponent],
  imports: [CommonModule], // include CommonModule in 'imports'
  providers: [],
})
export class YourFeatureModule {}

希望这有帮助

您的功能模块是否导入了
@angular/common
?@AlexanderStaroselsky-是。它就在那里:从'@angular/common'导入{CommonModule};但是它也存在于
@NgModule()
导入:[CommonModule]
中吗?@AlexanderStaroselsky-对不起,我不明白。我该怎么办?