[英]Ionic 3 - Typescript error: An arithmetic operand must be of type 'any', 'number' or an enum type
[英]Typescript type of any gives error at Ionic 2
我對下一個錯誤有疑問:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in build/pages/search/search.html:17:14
ORIGINAL EXCEPTION: Cannot find a differ supporting object 'function () {
return [
{
"wrapperType": "track",
"kind": "song",
"artistId": 5869117,
"collectionId": 459904774,
"trackId": 459904911,
"artistName": "Lil Wayne",
"collectionName": "Tha Carter IV (Deluxe Edition)",
"trackName": "John (feat. Rick Ross)",
"collectionCensoredName": "Tha Carter IV (Deluxe Edition)",
"trackCensoredName": "John (feat. Rick Ross)",
"artistViewUrl": "https://itunes.apple.com/us/artist/lil-wayne/id5869117?uo=4",
"collectionViewUrl": "https://itunes.apple.com/us/album/john-feat.-rick-ross/id459904774?i=459904911&uo=4",
"trackViewUrl": "https://itunes.apple.com/us/album/john-feat.-rick-ross/id459904774?i=459904911&uo=4",
"previewUrl": "http://a1557.phobos.apple.com/us/r1000/085/Music/de/c6/37/mzm.vjfeqrjw.aac.p.m4a",
"artworkUrl30": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/30x30bb.jpg",
"artworkUrl60": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/60x60bb.jpg",
"artworkUrl100": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/100x100bb.jpg",
"collectionPrice": 11.99,
"trackPrice": 1.29,
"releaseDate": "2011-08-29T07:00:00Z",
"collectionExplicitness": "explicit",
"trackExplicitness": "explicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 19,
"trackNumber": 9,
"trackTimeMillis": 286973,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Hip-Hop/Rap",
"contentAdvisoryRating": "Explicit",
"isStreamable": true
}
];
}' of type 'function'. NgFor only supports binding to Iterables such as Arrays. ORIGINAL STACKTRACE: Error: Cannot find a differ supporting object 'function () {
return [
{
"wrapperType": "track",
"kind": "song",
"artistId": 5869117,
"collectionId": 459904774,
"trackId": 459904911,
"artistName": "Lil Wayne",
"collectionName": "Tha Carter IV (Deluxe Edition)",
"trackName": "John (feat. Rick Ross)",
"collectionCensoredName": "Tha Carter IV (Deluxe Edition)",
"trackCensoredName": "John (feat. Rick Ross)",
"artistViewUrl": "https://itunes.apple.com/us/artist/lil-wayne/id5869117?uo=4",
"collectionViewUrl": "https://itunes.apple.com/us/album/john-feat.-rick-ross/id459904774?i=459904911&uo=4",
"trackViewUrl": "https://itunes.apple.com/us/album/john-feat.-rick-ross/id459904774?i=459904911&uo=4",
"previewUrl": "http://a1557.phobos.apple.com/us/r1000/085/Music/de/c6/37/mzm.vjfeqrjw.aac.p.m4a",
"artworkUrl30": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/30x30bb.jpg",
"artworkUrl60": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/60x60bb.jpg",
"artworkUrl100": "http://is4.mzstatic.com/image/thumb/Music/v4/c8/d2/f9/c8d2f98d-d2a8-35d0-fcd1-7adffc2560a9/source/100x100bb.jpg",
"collectionPrice": 11.99,
"trackPrice": 1.29,
"releaseDate": "2011-08-29T07:00:00Z",
"collectionExplicitness": "explicit",
"trackExplicitness": "explicit",
"discCount": 1,
"discNumber": 1,
"trackCount": 19,
"trackNumber": 9,
"trackTimeMillis": 286973,
"country": "USA",
"currency": "USD",
"primaryGenreName": "Hip-Hop/Rap",
"contentAdvisoryRating": "Explicit",
"isStreamable": true
}
];
}' of type 'function'. NgFor only supports binding to Iterables such as Arrays.
at new BaseException (http://localhost:8100/build/js/app.bundle.js:1805:23)
at NgFor.set [as ngForOf] (http://localhost:8100/build/js/app.bundle.js:540:27)
at DebugAppView._View_SearchPage0.detectChangesInternal (SearchPage.template.js:143:30)
at DebugAppView.AppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:29958:14)
at DebugAppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:30063:44)
at DebugAppView.AppView.detectViewChildrenChanges (http://localhost:8100/build/js/app.bundle.js:29984:19)
at DebugAppView.AppView.detectChangesInternal (http://localhost:8100/build/js/app.bundle.js:29969:14)
at DebugAppView.AppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:29958:14)
at DebugAppView.detectChanges (http://localhost:8100/build/js/app.bundle.js:30063:44)
at ViewRef_.detectChanges (http://localhost:8100/build/js/app.bundle.js:30401:65) ERROR CONTEXT [object Object]
這是我的代碼:
我想這與itemResults的類型有關:any; 我確實放置了任何東西,但仍然給我錯誤。 這是帶有打字稿的ionic 2應用程序,如果有人可以幫助我,請給我一些提示。
我想你可能是說:
this.itemResults = this.getResults();//notice the paranthesis .. this is how you call the method.
您可能還想使用$onInit
方法而不是構造函數
$onInit(){
this.itemResults = this.getResults();
}
構造函數永遠不要加載數據或有任何副作用。
因為您正在執行this.itemResults = this.getResults;
如果沒有括號, itemResults
類型為type的對象分配給itemResults
,這就是錯誤提示的原因:
找不到類型為“功能”的其他支持對象 “功能(){...}”。 NgFor僅支持綁定到Iterables,例如數組。
那行代碼應該是this.itemResults = this.getResults();
為了執行該方法並將結果分配給itemResults
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.