我是angular4的初学者,并且正在尝试将输入文本数据传递给组件类的方法。我的代码如下:
<div class="container">
<form class="jumbotron">
<div class="form-group">
<h3 class="ui header">Add a Link</h3>
<label for="Title">Title:</label>
<input name="title" class="form-control" #newtitle" >
</div>
<div class="form-group">
<label for="Link">Link:</label>
<input name="link" class="form-control" #newlink" >
</div>
<button (click)="addArticle(newtitle, newlink)" class="btn btn-success pull-right">Submit Link</button>
</form>
在组件类中我有这个函数:
class RedditApp{
addArticle(title: HTMLInputElement, link: HTMLInputElement): void{
console.log(`Adding article ${title.value} and link: ${link.value}`);
}
}
此代码适用于角度2.0,但4.0浏览器调试工具不显示任何内容。请建议。我应该使用ng-Model for angular4吗? PS:我已经从表格标签中删除了ng-controller =“AppComponent”..但仍然不起作用..