2017-06-15 9 views
0

角度4のエラーになります。(Angular-CLI)、 TypeError: Cannot read property 'value' of undefinedです。だから、Angular 1から来ているAngular 4が初めてです。あなたのお手伝いに感謝します。前もって感謝します。TypeError:角度4で未定義のプロパティ '値'を読み取ることができません。

ここに私のコードです。参照変数とパラメータ渡されたの

app.component.html

<!-- using semantic-ui --> 
<form class="ui large form segment"> 
    <h3 class="ui header">Add a link</h3> 
    <!-- added the title --> 

    <div class="field"> 
    <label for="title">Title:</label> 
    <input name="title" #newtitle> 
    </div> 
    <!-- added the link --> 
    <div class="field"> 
    <label for="link">Link:</label> 
    <input name="link" #newLink> 
    </div> 
    <!--added the button --> 

    <button (click)="addArticle(newTitle, newLink)" class="ui positive right floated button"> 
    Submit Link 
    </button> 

</form> 

app.component.ts

import { Component } from '@angular/core'; 

@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}`); 
    return false; 
    } 
} 

答えて

0

あなたのケースでは一致していません。 <input name="title" #newtitle><input name="title" #newTitle>に変更してください。addArticlenewTitleを大文字で入力してください。

+1

うわー、少し間違いがありました。私の男に感謝! –

関連する問題