1
私はAngularを初めて使用しています。私はFelipe Couryのチュートリアルに従っています。 (最初の角度2のWebアプリケーションを書く)の章では、彼は ".value"を使用して、入力するタイトルとリンクを表示します。彼のためにはうまくいきましたが、私のシステムでは "ERROR TypeError:未定義のプロパティ 'value'を読み取れません。私は4.50に私の角度cliをアップグレードしたので、私はそれがわからない。 あなたが解決策をお持ちでしたら親切に私を助けてください。エラーTypeError:未定義のプロパティ 'value'を読み取ることができません
これは
app.component.ts
import { Component } from '@angular/core';
import { Article } from 'app/article/article.model';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
addArticle(title: HTMLInputElement, link: HTMLInputElement): boolean {
console.log(`Adding article title: ${title.value} and link:
${link.value}`);
this.articles.push(new Article (title.value, link.value, 0));
title.value='';
link.value='';
return false;
}
articles:Article[];
constructor() {
this.articles = [
new Article ('Angular 2', 'http://www.angular.io', 3),
new Article ('Fullstack', 'http://www.fullstack.io', 10),
new Article ('Anguar Home page', 'http://www.angular.io', 4)
]
}
}
これはapp.component.html
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" #newlimk>
</div>
<button (click)="addArticle(newtitle, newlink)"
class="ui positive right floated button">
Submit link
</button>
</form>
<div class="ui grid posts">
<app-article
*ngFor="let foobar of articles"
[article]="foobar">
</app-article>
</div>
おかげで私のコードです!