0
Observables를 처음 사용했습니다. 그래서 여기 내가 내부의 recipeList를 인쇄 할 때 내 문제는 내 코드변수에 데이터를 등록 할 수 없습니다.
recipesList:Recipe[];
private recipes;
constructor(private shoppingService:ShoppingListService,private http:Http){
this.getRecipesFromUrl().subscribe((data)=>{
this.recipesList=data;
console.log(this.recipesList);//printing array containing recipes
});
console.log(this.recipesList);//printing undefined
}
인 나는 그것의 표시 정의되지 않은 외부 인쇄하고 때 내가 조리법을 받고 있지만 오전에 가입. recipeList에 데이터를 저장하는 방법 다른 방법으로도 데이터에 액세스 할 수 있습니다.
CONSOLE.LOG을 할 수있는 구독하고 기다려야한다. 데이터가로드 된 후에 recipeList에 대한 액세스가 필요한 모든 메소드를 호출해야합니다. – LLai
복제본에서와 같이 콜백 (구독) 내부에서 원하는/원하는 것을해야합니다. – Alex