質問編集履歴

1

componentとエラー文の追加

2018/11/20 00:36

投稿

rinimaruranran
rinimaruranran

スコア36

test CHANGED
File without changes
test CHANGED
@@ -32,77 +32,373 @@
32
32
 
33
33
  ```HTML
34
34
 
35
+ ■■■ @index.html ■■■
36
+
37
+ :(省略)
38
+
39
+ <body>
40
+
41
+ <app-root>Loading...</app-root>
42
+
43
+ </body>
44
+
45
+ </html>
46
+
47
+
48
+
49
+
50
+
51
+ ■■■ @app.component.html ■■■
52
+
53
+ <div class="main">
54
+
55
+ <div class="title">
56
+
57
+ <h1>{{title}}</h1>
58
+
59
+ </div>
60
+
61
+ <my-dashboard></my-dashboard>
62
+
63
+ </div>
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+ ■■■ @dashboard.component.html ■■■
72
+
73
+ ```
74
+
35
75
  <div class="search">
36
76
 
77
+ <div class="search_engine">
78
+
37
- <!-- ■■■■■■■■ ここで入力して ■■■■■■■■ -->
79
+ ■■■■■■■■ ここで入力して ■■■■■■■■
38
80
 
39
81
  <form>
40
82
 
41
- <input id="dataId" name="dataId" type="text" [(ngModel)]="dataId" #dataId="ngModel" />
83
+ <input id="hogeId" name="hogeId" type="text" [(ngModel)]="hogeId" #hogeId="ngModel" />
42
84
 
43
85
  </form>
44
86
 
87
+
88
+
45
89
  </div>
46
90
 
91
+ <div class="search_submit">
92
+
93
+ 送信
94
+
47
- <div>送信</div>
95
+ </div>
48
96
 
49
97
  </div>
50
98
 
99
+ <div class="search_result">
100
+
101
+ <div class="search_result_title">
102
+
103
+ <h3>検索結果</h3>
104
+
51
- <ul>
105
+ </div>
106
+
52
-
107
+ </div>
108
+
109
+ <ul class="search_result_list">
110
+
111
+ <li>{{hogeId}}</li>
112
+
53
- <li><div>{{data.name}}</div></li>
113
+ <li>{{hogeTitle}}</li>
54
114
 
55
115
  </ul>
56
116
 
57
-
58
-
59
117
  </div>
60
118
 
119
+
120
+
121
+
122
+
123
+ ```TypeScript
124
+
125
+ ■■■ @app.module.ts ■■■
126
+
127
+ import { BrowserModule } from '@angular/platform-browser';
128
+
129
+ import { NgModule } from '@angular/core';
130
+
131
+ import { FormsModule } from '@angular/forms';
132
+
133
+ import { HttpModule,JsonpModule} from '@angular/http';
134
+
135
+ import { DashboardComponent } from './component/dashboard/dashboard.component';
136
+
137
+ import { AppComponent } from './app.component';
138
+
139
+ import {DataService} from './services/data.service';
140
+
141
+
142
+
143
+ @NgModule({
144
+
145
+ declarations: [
146
+
147
+ AppComponent,
148
+
149
+ DashboardComponent
150
+
151
+ ],
152
+
153
+ imports: [
154
+
155
+ BrowserModule,
156
+
157
+ HttpModule,
158
+
159
+ JsonpModule,
160
+
161
+ FormsModule
162
+
163
+ ],
164
+
165
+ providers: [
166
+
167
+ DataService
168
+
169
+ ],
170
+
171
+ bootstrap: [AppComponent]
172
+
173
+ })
174
+
175
+ export class AppModule { }
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+ ■■■ @app.component.ts ■■■
184
+
185
+ import { Component } from '@angular/core';
186
+
187
+
188
+
189
+ @Component({
190
+
191
+ selector: 'app-root',
192
+
193
+ templateUrl: './app.component.html',
194
+
195
+ styleUrls: ['./app.component.css']
196
+
197
+ })
198
+
199
+ export class AppComponent {
200
+
201
+ title = 'Hoge Information Searcher';
202
+
203
+ hogeId = "";
204
+
205
+ }
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+ ■■■ @dashboard.component.ts ■■■
214
+
215
+ import {Component, OnInit} from "@angular/core";
216
+
217
+ import {Data} from "../../data";
218
+
219
+ import {DataService} from "../../services/data.service";
220
+
221
+
222
+
223
+ @Component({
224
+
225
+ selector: 'my-dashboard',
226
+
227
+ templateUrl: './dashboard.component.html',
228
+
229
+ styleUrls: ['./dashboard.component.css']
230
+
231
+ })
232
+
233
+
234
+
235
+ export class DashboardComponent implements OnInit{
236
+
237
+
238
+
239
+ hogeId = '検索結果';
240
+
241
+ hogeTitle = '検索結果';
242
+
243
+
244
+
245
+ constructor(private dataService: DataService){}
246
+
247
+
248
+
249
+ dataList : Data[];
250
+
251
+
252
+
253
+ ngOnInit(): void {
254
+
255
+ this.dataService.data().subscribe(
256
+
257
+ result => this.setDatas(result),
258
+
259
+ error => alert('通信エラー' + error)
260
+
261
+ );
262
+
263
+ }
264
+
265
+
266
+
267
+ setDatas(result): void {
268
+
269
+ if(result.error) {
270
+
271
+ alert('Web APIエラー' + result.message);
272
+
273
+ }
274
+
275
+
276
+
277
+ this.hogeId = result.data.hogeId;
278
+
279
+ this.hogeTitle = result.data.hogeTitle;
280
+
281
+ }
282
+
283
+ }
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+ ■■■ @data.service.ts ■■■
292
+
293
+ import { Injectable } from '@angular/core';
294
+
295
+ import { Http, Jsonp, RequestOptionsArgs, RequestOptions, URLSearchParams} from '@angular/http';
296
+
297
+ import {Observable} from "rxjs/Observable";
298
+
299
+ import "rxjs/add/operator/map";
300
+
301
+
302
+
303
+ import { Data } from '../data';
304
+
305
+
306
+
307
+ @Injectable()
308
+
309
+ export class DataService {
310
+
311
+
312
+
313
+ private datasUrl = 'http://localhost:8080/sampleData/data';
314
+
315
+
316
+
317
+ constructor(private http: Http, private jsonp: Jsonp) { }
318
+
319
+
320
+
321
+ data(): Observable<Data> {
322
+
323
+ let option : RequestOptions;
324
+
325
+ option = this.setHttpGetParam(this.datasUrl);
326
+
327
+
328
+
329
+ return this.http.post(this.datasUrl, "", option)
330
+
331
+ .map((response) => {
332
+
333
+ let content;
334
+
335
+ let obj = response.json();
336
+
337
+ content = {
338
+
339
+ error: null,
340
+
341
+ data: obj
342
+
343
+ };
344
+
345
+ console.log(response);
346
+
347
+ return content;
348
+
349
+
350
+
351
+ });
352
+
353
+
354
+
355
+ }
356
+
357
+ private setHttpGetParam(url: string): RequestOptions {
358
+
359
+ let param = new URLSearchParams();
360
+
361
+ ■■■■■■■■ 結果をここで使いたい ■■■■■■■■
362
+
363
+ param.set("hogeId", #hogeId); (←エラー文の36行目はここです)
364
+
365
+ param.set("countryCd", "1");
366
+
367
+ let options: RequestOptionsArgs = {
368
+
369
+ method: "post",
370
+
371
+ url: url,
372
+
373
+ search: param,
374
+
375
+ };
376
+
377
+ return new RequestOptions(options);
378
+
379
+ }
380
+
381
+
382
+
383
+ }
384
+
61
385
  ```
62
386
 
63
387
 
64
388
 
65
389
 
66
390
 
67
- ```TypeScript
68
-
69
- :省略
70
-
71
- @Injectable()
72
-
73
- export class DataService {
74
-
75
- :省略
76
-
77
- private setHttpGetParam(url: string): RequestOptions {
78
-
79
- let param = new URLSearchParams();
80
-
81
- // ■■■■■■■■ 結果をここで使いたい ■■■■■■■■
82
-
83
- param.set("dataId", #dataId);
84
-
85
- let options: RequestOptionsArgs = {
86
-
87
- method: "post",
88
-
89
- url: url,
391
+ ### エラー内容
90
-
91
- search: param,
92
-
93
- };
94
-
95
- return new RequestOptions(options);
96
-
97
- }
98
-
99
- }
100
392
 
101
393
  ```
102
394
 
103
-
395
+ ERROR in /Users/rinimaruranran/sample/src/main/resources/static/angular/src/app/services/data.service.ts (36,26): Invalid character.
396
+
397
+
398
+
104
-
399
+ ERROR in /Users/rinimaruranran/sample/src/main/resources/static/angular/src/app/services/data.service.ts (36,27): Cannot find name 'hogeId'.
400
+
105
-
401
+ ```
106
402
 
107
403
 
108
404