我已经宣布一个属性在角2 Foobar
组件调用foobar
:角2组分属性遮蔽
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-foobar',
templateUrl: './foobar.component.html',
styleUrls: ['./foobar.component.css']
})
export class FoobarComponent implements OnInit {
foobar= 'test';
ngOnInit() {
}
}
然后在foobar.component.html
文件I输出属性是这样的:
<div>
<br>
{{foobar}}
</div>
并输出字test
,但是,一旦我添加了ID为foobar
的元素:
<div>
<br>
{{foobar}}
<br>
<input type="text" #foobar>
</div>
我不再能够从组件获得价值,并且它输出[object HTMLInputElement]
,因为它被输入字段ID遮蔽。
如何在不更改组件属性名称和输入字段ID的情况下从组件获取值?
组件没有变量,它们具有属性。 – 2017-06-22 12:15:56
@torazaburo谢谢,我纠正了它。 – Benas