Angular 2とTypeScriptの世界に入り込み、このエラーに遭遇しました。あなたがどこかに_isScalarを設定できるように見えます...これがどこにあるべきかわかりません。TypeScript SomeArray [] 'はタイプ' Observable <SomeArray[]> 'に割り当てられません
私は次のようなエラー(コード内のコメント行を参照してください)取得しています:
タイプの格付けは、[] '「観察可能な」型に代入できません。
静的メソッドを使用していますreturn Observable.of<Rating[]>(choices);
:あなたが好きな、観察を返す必要が
import { Injectable } from '@angular/core';
import { Inject } from '@angular/core';
import { Jsonp, JsonpModule, Http } from '@angular/http';
import { Rating } from './rating.model';
import { Observable } from 'rxjs/Rx';
import { DOCUMENT } from '@angular/platform-browser'
import { IODataList } from '@microsoft/sp-odata-types';
import { SPHttpClient, SPHttpClientConfigurations, SPHttpClientConfiguration, SPHttpClientResponse, ODataVersion, ISPHttpClientConfiguration } from '@microsoft/sp-http';
@Injectable()
// See: http://www.telerik.com/kendo-angular-ui/components/dropdowns/dropdownlist/#toc-data-binding
export class RatingsService {
//constrauctor(private jsonp: Jsonp) { }
constructor(@Inject(Http) private http: Http, @Inject(DOCUMENT) private document: any) { }
//var url = this.context.pageContext.web.absoluteUrl + `/_api/web/lists?$filter=Hidden eq false`;
private choices: Array<Rating> = [];
public fetchData(): Observable<Rating[]> {
console.log("BGW: Document location = " + document.location.href);
// var url = this.context.pageContext.web.absoluteUrl + `/_api/web/lists?$filter=Hidden eq false`;
//var response = this.jsonp.get(url); //.map((response => response.json()));
console.log("BGW: Ratings choices url = " + url);
//var choices: Array<Rating> = new Array<Rating>();
var choices: Array<Rating> = new Array<Rating>();
// choices._isScalar = true;
//let choices: Observable<Rating[]> = new Observable<Rating>();
if (document.location.href.indexOf("localhost") > 0)
{
// Send dummy data to the form.
console.log("BGW: Local workbench in use");
choices.push(new Rating("High"));
choices.push(new Rating("Medium"));
choices.push(new Rating("Low"));
return choices; // *** ISSUE HERE ***
}
else
{
var url = "https://somewhere.sharepoint.com/sites/Development/Subsite/_api/web/lists/GetByTitle('Requirements')/fields?$filter=EntityPropertyName%20eq%20%27Requirement_x0020_Rating%27";
console.log("BGW: Ratings choices url = " + url);
// Ref: http://chariotsolutions.com/blog/post/angular2-observables-http-separating-services-components/
var response = this.http.get(url).map((response => response.json()));
console.log("BGW: response = " + JSON.stringify(response));
return response.map((choices: Array<any>) => {
if (choices) {
choices.forEach((choice) => {
choices.push(new Rating(choice));
});
}
return choices;
});
}
}
}
@webtechy、あなたの問題にお答えしましたか?もしそうなら、あなたは答えの投票の下にある灰色のダニをクリックして親切に答えを受け入れるでしょうか? :) http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Alex