亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么這個數據不顯示

為什么這個數據不顯示

C#
哆啦的時光機 2022-11-21 21:32:12
我正在學習 Angular,我從 Visual Studio 中名為 Angular5TF1 的示例項目開始。示例中有一個名為“獲取數據”的菜單選項,它模擬從服務器檢索數據。我復制了這個方法及其類和頁面,并試圖讓它從我寫的方法中檢索數據 - 它不起作用..我從示例中復制了“FetchData”方法及其類和頁面,并試圖讓它從我編寫的方法中檢索數據。返回值顯示正確的值,但當我嘗試顯示數組中的值之一時,它返回未定義。此外,我返回 10 個值,for 循環打印 10 行,但它們都是空白的。有人可以解釋原因并幫助我完成這項工作嗎?提前致謝。從組件 html:<h1>Interests</h1><div class="col-lg-12">&nbsp;</div><div class="col-lg-10">    Interest:&nbsp;<input type="text" id="txtInterest" />&nbsp;<button (click)="test()">Add...</button></div><div class="col-lg-12">&nbsp;</div><div class="col-lg-12">&nbsp;</div><div class="col-lg-12">    <p *ngIf="!personalInterests"><em>Loading Interests, Please Wait...</em></p></div><table class='table' *ngIf="personalInterests">    <thead>        <tr>            <th>Interest Name</th>        </tr>    </thead>    <tbody>        <tr *ngFor="let interest of personalInterests">            <td>{{ interest.InterestName }}</td>        </tr>    </tbody></table>從組件import { Component, Inject } from '@angular/core';import { Http } from '@angular/http';//import { forEach } from '@angular/router/src/utils/collection';@Component({    selector: 'interests',    templateUrl: './interests.component.html'})export class InterestsComponent {    public personalInterests: PersonalInterest[];    constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {        http.get(baseUrl + 'api/Interest/Interests').subscribe(result => {            this.personalInterests = result.json() as PersonalInterest[];        }, error => console.error(error));    }    public test() {        alert(this.personalInterests[1].InterestName);    }}interface PersonalInterest {    InterestName: string;}
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

使用 Camel Case 解決了這個問題。



查看完整回答
反對 回復 2022-11-21
  • 1 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號