0
我正在構建一項新功能,使用戶可以使用輸入來調整iframe的大小。我有一個iframe
,我想根據input type="number"
來調整它的寬度。我想用指令的方式如何使用angular4上的輸入來調整iframe寬度?
@Component({
selector: "demo-iframe",
template: `
<form>
<input type="number" [customPx]="`test`">px
<button type="submit">Adjust width</button>
</form>
`
})
export class DemoIframeCmp {
@Input() public customPx: string;
public ngOnInit() {
if (this.customPx) {
console.log('YES', this.customPx);
} else {
console.log('NOPE', this.customPx);
}
}
}
這樣做的,但後來我發現我的輸入沒有customPx
ATTR控制檯上的錯誤。我的問題是:
- 是
Directive
是一個很好的方法嗎? - 對我的功能有更好的方法嗎?
阿爽!謝謝! – ivanasetiawan