-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
437 additions
and
442 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"/api":{ | ||
"target":"http://localhost:8000" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,3 @@ | |
</div> | ||
</div> | ||
<app-footer></app-footer> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
auction/src/app/product-detail/product-detail.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { WebSocketService } from './web-socket.service'; | ||
|
||
describe('WebSocketService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [WebSocketService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([WebSocketService], (service: WebSocketService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {Observable} from "rxjs"; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class WebSocketService { | ||
|
||
ws: WebSocket; | ||
|
||
constructor() { | ||
} | ||
|
||
createObservableSocket(url: string): Observable<any> { | ||
this.ws = new WebSocket(url); | ||
return new Observable( | ||
observer =>{ | ||
//什么时候发生下一个元素 | ||
this.ws.onmessage = (event) => observer.next(event.data); | ||
//什么时候抛一个异常 | ||
this.ws.onerror = (event) => observer.error(event); | ||
//什么时候发出流结束的信号 | ||
this.ws.onclose = (event) => observer.complete(); | ||
|
||
} | ||
); | ||
} | ||
|
||
sendMessage(message:string){ | ||
this.ws.send(message); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<button (click)="sendMessageToserver()">点击发送webSocket消息</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { WebSocketComponent } from './web-socket.component'; | ||
|
||
describe('WebSocketComponent', () => { | ||
let component: WebSocketComponent; | ||
let fixture: ComponentFixture<WebSocketComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ WebSocketComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(WebSocketComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import {WebSocketService} from "../shared/web-socket.service"; | ||
|
||
@Component({ | ||
selector: 'app-web-socket', | ||
templateUrl: './web-socket.component.html', | ||
styleUrls: ['./web-socket.component.css'] | ||
}) | ||
export class WebSocketComponent implements OnInit { | ||
|
||
constructor(private wsService:WebSocketService) { } | ||
|
||
ngOnInit() { | ||
this.wsService.createObservableSocket("ws://localhost:8085") | ||
.subscribe( | ||
data => console.log(data), | ||
err => console.log(err), | ||
() => console.log("流已经结束") | ||
) | ||
} | ||
|
||
sendMessageToserver(){ | ||
this.wsService.sendMessage("Hello from client"); | ||
} | ||
|
||
} |