控制器未实现字符串插值
controller not actualize string interpolation
我遇到了问题
我的hellow.component.html是:
<form>
<input ng-model="hello" type="text">
</form>
<p>{{hello}}</p>
和hellow.component.ts是:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-hellow',
templateUrl: './hellow.component.html',
styleUrls: ['./hellow.component.css']
})
export class HellowComponent implements OnInit {
hello:string ='';
constructor() { }
ngOnInit() {
}
}
你能回答吗
如果我在输入中写了一些东西,{{hello}} 字符串插值不会被控制器实现。
你能帮我解决这个问题吗?
也试过:
<input [(ngModel)]="hello" type="text">
非常感谢。
您是否导入了 FormsModule
?
import { FormsModule } from '@angular/forms';
在标签内使用 ngModel
时,您还需要提供一个名称属性,以便可以使用该名称向父窗体注册该控件。
试试这个。
<form>
<input name="hello" [(ngModel)]="hello" type="text">
</form>
<p>{{hello}}</p>
问题已解决
我忘记在输入标签
中添加 name="hello"
属性
非常感谢您的帮助!
我遇到了问题
我的hellow.component.html是:
<form>
<input ng-model="hello" type="text">
</form>
<p>{{hello}}</p>
和hellow.component.ts是:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-hellow',
templateUrl: './hellow.component.html',
styleUrls: ['./hellow.component.css']
})
export class HellowComponent implements OnInit {
hello:string ='';
constructor() { }
ngOnInit() {
}
}
你能回答吗
如果我在输入中写了一些东西,{{hello}} 字符串插值不会被控制器实现。
你能帮我解决这个问题吗?
也试过:
<input [(ngModel)]="hello" type="text">
非常感谢。
您是否导入了 FormsModule
?
import { FormsModule } from '@angular/forms';
在标签内使用 ngModel
时,您还需要提供一个名称属性,以便可以使用该名称向父窗体注册该控件。
试试这个。
<form>
<input name="hello" [(ngModel)]="hello" type="text">
</form>
<p>{{hello}}</p>
问题已解决
我忘记在输入标签
中添加 name="hello"
属性
非常感谢您的帮助!