質問編集履歴

1

問題解決後のコードの追記

2017/02/09 12:06

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -169,3 +169,149 @@
169
169
 
170
170
 
171
171
  templateにある<h3>Title: {{question.title}}</h3>などが正常に動作させるには、どこを修正する必要があるでしょうか。
172
+
173
+
174
+
175
+
176
+
177
+ ###[17/02/09 21:00 追記]表示できました!
178
+
179
+ 下記のようにコードを変更したところ、無事出力されました。
180
+
181
+
182
+
183
+ [src/pages/home/home.html]
184
+
185
+ ```html
186
+
187
+ <ion-header>
188
+
189
+ <ion-navbar>
190
+
191
+ <ion-title>
192
+
193
+ Ionic Blank
194
+
195
+ </ion-title>
196
+
197
+ </ion-navbar>
198
+
199
+ </ion-header>
200
+
201
+
202
+
203
+ <ion-content padding>
204
+
205
+ <div *ngFor="let question of questions;">
206
+
207
+ <h3>Name: {{question.title}}</h3>
208
+
209
+ <h3>Description: {{question.question_description}}</h3>
210
+
211
+ </div>
212
+
213
+ </ion-content>
214
+
215
+ ```
216
+
217
+
218
+
219
+ [src/pages/home/home.ts](無駄多そう…)
220
+
221
+ ```typescript
222
+
223
+ import {Component, OnInit} from '@angular/core';
224
+
225
+ import {NavController} from 'ionic-angular';
226
+
227
+ import {JsonData} from '../../providers/json-data';
228
+
229
+
230
+
231
+
232
+
233
+ @Component({
234
+
235
+ selector: 'page-home',
236
+
237
+ templateUrl: 'home.html'
238
+
239
+ })
240
+
241
+ export class HomePage implements OnInit {
242
+
243
+
244
+
245
+ constructor(public navCtrl: NavController, public dataService: JsonData) {
246
+
247
+ }
248
+
249
+
250
+
251
+ questions: any;
252
+
253
+
254
+
255
+ ngOnInit() {
256
+
257
+ this.getQuestion();
258
+
259
+ }
260
+
261
+
262
+
263
+ getQuestion() {
264
+
265
+ this.dataService.getData().subscribe(questions => {
266
+
267
+ this.questions = questions.questions;
268
+
269
+ console.log(questions);
270
+
271
+ });
272
+
273
+ }
274
+
275
+ ```
276
+
277
+
278
+
279
+ [src/providers/json-data.ts]
280
+
281
+ ```typescript
282
+
283
+ import { Injectable } from '@angular/core';
284
+
285
+ import { Http } from '@angular/http';
286
+
287
+ import 'rxjs/add/operator/map';
288
+
289
+
290
+
291
+ @Injectable()
292
+
293
+ export class JsonData {
294
+
295
+
296
+
297
+ constructor(public http: Http) {}
298
+
299
+
300
+
301
+ getData(){
302
+
303
+ return this.http.get('../assets/data/data.json')
304
+
305
+ .map(res => res.json());
306
+
307
+ };
308
+
309
+ }
310
+
311
+ ```
312
+
313
+ ![![イメージ説明](2491a3a826c5d7a84ae0305c60304fc3.png)]
314
+
315
+ 無事出力できました。
316
+
317
+ ngOnInitの存在や、それを継承させることをすっかり忘れていました。