[英]Angular2 addArticle is not a function
當單擊“提交”按鈕時,我在控制台中遇到此消息,並且是否有人可以幫助我如何將時刻從node_modules導入angula2項目!
我的app.component.html
<form class="ui large form segment">
<h3 class="ui header">Add a Link</h3>
<div class="field">
<label for="title">Title:</label>
<input name="title" #newtitle>
</div>
<div class="field">
<label for="link">Link:</label>
<input name="link" #newlink>
</div>
<div>
<button (click) ="addArticle(newtitle, newlink)" class="ui positive button">Submit link</button>
</div>
</form>
我的app.module.ts
export class AppModule {
addArticle(title: HTMLInputElement, link:HTMLInputElement): boolean{
console.log('title: ${title.value} and link: ${link.value}');
return false;
}
}
您已在app.module.ts中編寫了addArticle方法,應將其放在app.component.ts中
export class AppModule {
addArticle(title: HTMLInputElement, link:HTMLInputElement): boolean{
console.log('title: ${title.value} and link: ${link.value}');
return false;
}
}
在app.component.html中使用addArticle方法時將其移動到app.component.ts
export class AppComponent {
title = 'Okay, proceed .!';
names = [];
// myDate = Date;
constructor(){
this.names = ['Tuan','Mark','Kevin'];
// this.myDate = new Date();
}
addArticle(title: HTMLInputElement, link:HTMLInputElement): boolean{
console.log('title: ${title.value} and link: ${link.value}');
return false;
}
}
暫時使用以下導入
import {MomentModule} from 'angular2-moment/module';
在npm install angular2-moment
之后npm install angular2-moment
.. http://ngmodules.org/modules/angular2-moment
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.