- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试将 ngModel 发送回组件 onchange 以使其显示在控制台上。
Html 文件:尝试借助 log 方法来 console.log ngModel。
<form action="">
<div class="form-group">
<label for="firstname">First name</label>
<input type="text" id="firstName" name="firstName" #firstName = "ngModel"
(change)="log(ngModel)" ngModel
class="form-control"/>
</div>
<div class="form-group">
<label for="comment">Comment</label>
<textarea id="comment" cols="30" rows="10" class="formcontrol"></textarea>
</div>
<button class="btn btn-primary">Submit</button>
</form>
组件
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-form-contact',
templateUrl: './form-contact.component.html',
styleUrls: ['./form-contact.component.css']
})
export class FormContactComponent {
log(x){
console.log(x);
}
}
出现以下错误:
- No directive found with exportAs 'ngModel'. (name="firstName" #firstName = "ngModel")
- Property 'ngModel' does not exist on type 'FormContactComponent'. ((change)="log(ngModel)"ngModel)
有人可以指导我正确的方向吗?
另外,ngModel在这里是什么意思?我知道 [(ngModel)] 是一种双向绑定(bind)。[ngModel] 将是一个属性,(ngModelChange) 将是事件,它们一起形成 2way 绑定(bind)。独立的 ngModel 代表什么?
最佳答案
使用您的代码,您创建了一个 template-reference-variable 。这意味着 firstName
现在具有指令 ngModel
的属性。
我认为这不是您想要的。也许这样的东西适合你:
<input type="text" name="firstName" (ngModelChange)="log($event)" class="form-control"/>
关于Angular 在更改时将 ngModel 传递给组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64553424/
我对 Swift 比较陌生。我在 pickerView 中使用 PFQuery 时遇到了问题。 我正在尝试实现一个 2 组件 pickerView,如下所示: 组件 0:组件 1 “A”:“Altiv
packageUrl="http://192.168.0.112" packageUrl_line=`grep -n "packageUrl" ${file} | head -1 | cut -d "
我遇到了一个烦人的问题。我正在做一个消息传递应用程序。在消息页面中,当用户滚动到顶部时,一旦最上面的单元格可见,它将加载更多消息以显示。因为在加载更多消息时, TableView 的位置在顶部(内容偏
可以屏蔽吗 Jsoup.connect("http://xyz.com").get().html(); 作为对网站的浏览器调用? 我尝试构建一个壁纸下载工具,但在从服务器下载页面时遇到问题。 如果我下
IntelliJ 给了我以下代码的提示: val l = List(0, "1", 2, "3") l.foreach{_ match {case xx:Int => println(xx);case
我正在尝试读取使用三个水平点表示缺失值的 excel 文件,例如... https://population.un.org/wpp/Download/Files/1_Indicators%20(Sta
我有一个 NSPopupButton,其内容绑定(bind)到 NSArray,假设该数组是 @[ @"Option 1", @"Option 2" ]; 其选择的对象绑定(bind)
大家好,我希望您能回答这个问题:) 基本上,我的index.html中有一些html 5视频,并且会自动播放背景音频。 我想发生的是在播放视频标签时将背景音频减少到50%。如果可能的话,如果我可以使用
需要一点帮助来解决这个问题。我的目标是拥有一个可执行的 jar 文件,它可以截取网页的屏幕截图,并且可以在 Windows 和 Linux 机器上运行。我尝试过使用 html2image 但 phan
我知道如何将 comboBox 值插入到 sql 中,但不知道如何在 sql 中用数字替换 comboBox 值。 这是我的组合框编码和处理按钮的一部分。 用户.java JComboBox com
我有一个像这样的 XML 片段: WEL SMIO 01/01/2015 12/31/9999 AAE 01/01/2015
好的,我知道每个人都认为 IFrame 不好,我知道这一点。但我“被要求”在极少数情况下使用一个。 所以我的问题是,当您有一个包含 IFrame 的 .aspx 页面,然后在该 IFrame 中有另一
我有一个 React 应用程序,我在其中使用 axios 库来获取一些值,并将它们设置为处于我状态的 javascript 对象数组 componentDidMount(){ axios.
我必须存储我的 HashMap通过Spring data导入数据库MySql。为了从 HashMap 检索数据,我使用键值,并且可能会发生键不存在的情况,在这种情况下,我必须避免使用 set 方法将值
我有 Size 模型,其中 value 作为字符串。我想根据 value 属性通过将其转换为十进制来排序 size。 has_many :sizes, -> {order 'value ASC'},这
嗨,我有一个 MYSQL 表,例如 PART{ part_id :long,Auto Increment parent_part_id :long root_part_id :long } 我需
我正在尝试将列名为“邮政编码”、“2010 年人口”、“Land-Sq-Mi”和“每平方英里密度”的 CSV 文件导入我的测试表,该表名为 derp--这就是我在开头使用 drop 语句的原因,这样我
我想写一个这样的存储过程: CREATE OR REPLACE FUNCTION my_function(param_1 text, param_2 text DEFAULT NULL::text)
我有一个 RecyclerView,在它之上,有一个 AdView。滚动 RecyclerView 时,我想将 Adview 留在固定位置。我该怎么做? 这是我打开应用程序时的 RecyclerVie
我有一个 UIScrollView,其中包含一个 UIView 容器,该容器包含多个 UITextField。 我想执行以下操作:如果我选择一个字段并且它位于键盘下方,则将文本字段提升到键盘上方 20
我是一名优秀的程序员,十分优秀!