[英]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.