Angular 角度误差NG8002:Can';t绑定到';ngStyle';因为它不是';t'的已知属性;分区';
在Angular-11中,我有以下代码: 密码-meter.component.ts: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
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-对不起,我不明白。我该怎么办?