非常简单,我有一个包含sting的组件Angular2在输入字段中单向数据绑定
我需要在输入fieid中显示此字符串。
我以为我需要这样但它不起作用。
// Component
import {Component} from "@angular/core";
@Component({
selector: 'my-component',
templateUrl: './my-compoent.template.html';
})
export class MyComponent{
constructor(){
}
myVar: string = "Hello World"
}
// HTML
<input type="text" ([ngModel])="myVar" >
使用'[(ngModel)] = “myVar的”'(或'[ngModel] = “myVar的”'如果只是单向绑定) – amal
真您ngModel语法错误 –
'[ngModel] =” myVar“'不起作用 – ttmt