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

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

可觀察類型錯誤:無法讀取未定義的屬性

可觀察類型錯誤:無法讀取未定義的屬性

青春有我 2019-07-30 17:18:26
可觀察類型錯誤:無法讀取未定義的屬性在我的Angular 2應用程序中,我收到一個錯誤:無法讀取undefined的屬性'title'。這是一個非常簡單的組件,只是試圖在這里工作。它擊中我的API控制器(奇怪地多次),它似乎在返回一個對象后點擊回調。我的console.log輸出了我期望的對象。這是完整的錯誤:TypeError: Cannot read property 'title' of undefined     at AbstractChangeDetector.ChangeDetector_About_0.detectChangesInRecordsInternal (eval at <anonymous> (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:10897:14), <anonymous>:31:26)     at AbstractChangeDetector.detectChangesInRecords (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8824:14)     at AbstractChangeDetector.runDetectChanges (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8807:12)     at AbstractChangeDetector._detectChangesInViewChildren (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8877:14)     at AbstractChangeDetector.runDetectChanges (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8811:12)     at AbstractChangeDetector._detectChangesContentChildren (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8871:14)     at AbstractChangeDetector.runDetectChanges (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8808:12)     at AbstractChangeDetector._detectChangesInViewChildren (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8877:14)     at AbstractChangeDetector.runDetectChanges (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8811:12)     at AbstractChangeDetector.detectChanges (http://localhost:55707/lib/angular2/bundles/angular2.dev.js:8796:12)該服務(about.service.ts):import {Http} from 'angular2/http';import {Injectable} from 'angular2/core';import {AboutModel} from './about.model';import 'rxjs/add/operator/map';@Injectable()export class AboutService {     constructor(private _http: Http) { }     get() {         return this._http.get('/api/about').map(res => {             console.log(res.json()); // I get the error on the line above but this code is still hit.             return <AboutModel>res.json();         });     }}
查看完整描述

3 回答

?
慕仙森

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

它看起來像你about.title在視圖中引用,about.htmlabout只有在http請求完成后才會實例化變量。為避免此錯誤,您可以about.html使用<div *ngIf="about"> ... </div>


查看完整回答
反對 回復 2019-07-30
  • 3 回答
  • 0 關注
  • 1595 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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