我根本无法弄清楚如何从Angular建立信号发送器连接。
在https://docs.microsoft.com/zh-cn/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc使用以下教程
我SignalR在vs2017中为现有的.Net 4.6解决方案添加了一个新的2.4.0项目。
我也有一个Angular 7应用程序,我SignalR通过它向其中添加了软件包npm install @aspnet/signalr
现在,我试图在客户端和服务器之间建立一个简单的连接,但无法弄清楚如何建立初始连接。
我的前端一直抛出异常:
core.js:15714 ERROR Error: Uncaught (in promise): Error: Cannot send data if the connection is not in the 'Connected' State.
Run Code Online (Sandbox Code Playgroud)
错误:如果连接未处于“已连接”状态,则无法发送数据。
在前端搜索组件中,我添加了一些测试字段:
core.js:15714 ERROR Error: Uncaught (in promise): Error: Cannot send data if the connection is not in the 'Connected' State.
Run Code Online (Sandbox Code Playgroud)
在我的ts文件中:
<mat-form-field>
<input matInput placeholder="message" [(ngModel)]="message">
</mat-form-field>
<button mat-button type="button" (click)="sendMessageToServer()"><span>Send</span></button>
<p *ngFor="let m of messages">{{m}}</p>Run Code Online (Sandbox Code Playgroud)
在C#端,我添加了一个SignalR Hub Class (v2) …