Angular 按钮';s禁用状态不反映IE中的基础变量
我已经在Angular 2中编写了一个信号器客户端应用程序。客户机实现了一个从信号器集线器调用的功能Angular 按钮';s禁用状态不反映IE中的基础变量,angular,Angular,我已经在Angular 2中编写了一个信号器客户端应用程序。客户机实现了一个从信号器集线器调用的功能connected。从集线器调用此函数时,只需将布尔变量connected设置为true。我使用此已连接的变量来控制按钮的启用\禁用状态。它在Firefox和Chrome中运行良好,但在IE button的启用/禁用状态下,并不反映connected变量的值 下面是ASP.NET web api中我的SignalR Hub类中的一个函数 public void Connect() { Cl
connected
。从集线器调用此函数时,只需将布尔变量connected
设置为true
。我使用此已连接的变量来控制按钮的启用\禁用状态。它在Firefox和Chrome中运行良好,但在IE button的启用/禁用状态下,并不反映connected
变量的值
下面是ASP.NET web api中我的SignalR Hub类中的一个函数
public void Connect()
{
Clients.Caller.connected();
}
在我的Angular2应用程序中,我有以下服务。
信号机测试.服务.ts
import { Injectable } from '@angular/core';
export class SignalrWindow extends Window {
$: any;
}
@Injectable()
export class SiglalrTestService {
private hubProxy: any;
private hubConnection: any;
private connected = false;
constructor(private window: SignalrWindow) {
if (this.window.$ === undefined || this.window.$.hubConnection === undefined) {
throw new Error("The variable '$' or the .hubConnection() function are not defined...please check the SignalR scripts have been loaded properly");
}
this.hubConnection = this.window.$.hubConnection();
this.hubConnection.url = 'http://localhost:18117/signalr';
this.hubProxy = this.hubConnection.createHubProxy('MyHub');
this.hubProxy.on("connected", () => {
this.connected = true;
console.log('Connected successfully....');
});
}
start(): void {
this.hubConnection.start()
.done(() => {
this.hubProxy.invoke('Connect');
})
.fail((error: any) => {
throw new Error("Failed to start connection" + error);
});
}
stop(): void {
this.hubConnection.stop();
this.connected = false;
}
get isConnected(): boolean {return this.connected;}
}
import {Component, OnInit} from '@angular/core';
import { SiglalrTestService } from './signalr-test.service';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit{
constructor(private signalrTest : SiglalrTestService){}
ngOnInit(): void {
}
startSignalR(){
this.signalrTest.start();
}
stopSignalR(){
this.signalrTest.stop();
}
get connectedToServer() : boolean{ return this.signalrTest.isConnected; }
}
应用程序组件.ts
import { Injectable } from '@angular/core';
export class SignalrWindow extends Window {
$: any;
}
@Injectable()
export class SiglalrTestService {
private hubProxy: any;
private hubConnection: any;
private connected = false;
constructor(private window: SignalrWindow) {
if (this.window.$ === undefined || this.window.$.hubConnection === undefined) {
throw new Error("The variable '$' or the .hubConnection() function are not defined...please check the SignalR scripts have been loaded properly");
}
this.hubConnection = this.window.$.hubConnection();
this.hubConnection.url = 'http://localhost:18117/signalr';
this.hubProxy = this.hubConnection.createHubProxy('MyHub');
this.hubProxy.on("connected", () => {
this.connected = true;
console.log('Connected successfully....');
});
}
start(): void {
this.hubConnection.start()
.done(() => {
this.hubProxy.invoke('Connect');
})
.fail((error: any) => {
throw new Error("Failed to start connection" + error);
});
}
stop(): void {
this.hubConnection.stop();
this.connected = false;
}
get isConnected(): boolean {return this.connected;}
}
import {Component, OnInit} from '@angular/core';
import { SiglalrTestService } from './signalr-test.service';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit{
constructor(private signalrTest : SiglalrTestService){}
ngOnInit(): void {
}
startSignalR(){
this.signalrTest.start();
}
stopSignalR(){
this.signalrTest.stop();
}
get connectedToServer() : boolean{ return this.signalrTest.isConnected; }
}
模板文件是
app.component.html
<div>
<h1>SignalR Test</h1>
<input type="button" [disabled]="connectedToServer" (click)="startSignalR()" value="Start" >
<input type="button" [disabled]="!connectedToServer" (click)="stopSignalR()" value="Stop" >
</div>
信号员测试
我正在使用AngularJS 2.0.1、SignalR 2.2.1和IE 11
顺便说一句,我已经把这个问题发布在