2
指示
無法綁定一個已知屬性
請參閱下面的代碼,不管我用
<dform [meta]="frmeta"></dform>
或<dform meta="{{frmeta}}"></dform>
我會得到一個錯誤到 「元」,因爲它不是「D-型」的已知財產。」
在編譯的代碼打字稿。任何一個人知道什麼是錯我的代碼?
DformComponent.ts
import { Component, Attribute } from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
@Component({
selector:'dform',
templateUrl:'DformComponent.html'
})
export class DformComponent{
frmdata:any;
constructor(fb:FormBuilder, @Attribute('meta') public meta:any){
// this.frmdata = fb.group({
// phone:["123456789", containsMagicWord]
// , ip:["192.168.137.169", containsMagicWord]
// });
console.log(this.meta);
debugger;
this.frmdata = fb.group(this.meta);
}
dosubmit(event:any){
console.log(this.frmdata.value);
}
}
DformComponent.html
<form [formGroup]="frmdata" (submit)="dosubmit($event)">
<inputmask formControlName="phone" mask="(___) ___ - ___"></inputmask>
<inputmask formControlName="ip" mask="___.___.___.___" ></inputmask>
<button type="submit">Post</button>
<pre>{{ frmdata.value|json }}</pre>
</form>
RootComponent.ts
import { Component } from '@angular/core';
function containsMagicWord(c: any) {
if(c.value.indexOf('magic') >= 0) {
return {
noMagic: true
}
}
// Null means valid, believe it or not
return null
}
@Component({
selector: 'body',
templateUrl: 'RootComponent.html'
})
export class RootComponent {
frmeta:any = {
phone:["123456789", containsMagicWord]
, ip:["192.168.137.169", containsMagicWord]
};
constructor(){
}
}
RootComponent.html
<dform meta="{{frmeta}}"></dform>
請添加確切的錯誤信息。 'X'和'Y'沒有幫助。 –
已添加,請檢查。 – mind1n
'[meta] =「frmeta」'的意圖或預期行爲是什麼? –