信号器客户端未填充angularjs指令
我有一个angularjs指令将使用信号器信号器客户端未填充angularjs指令,angularjs,angularjs-directive,signals,Angularjs,Angularjs Directive,Signals,我有一个angularjs指令将使用信号器 (function(){ "use strict"; angular.module('docsSimpleDirective', []) .controller('Controller', ['$scope', function($scope) { var hub = $.connection.realtimeFult; $.connection.h
(function(){
"use strict";
angular.module('docsSimpleDirective', [])
.controller('Controller', ['$scope', function($scope) {
var hub = $.connection.realtimeFult;
$.connection.hub.url = "http://localhost:39858/signalr";
$.connection.hub.start();
hub.client.faultOccured = function (location) {
console.log(location);
};
}])
.directive('myCustomer', function() {
return {
template: 'Name: {{customer.name}} Address: {{customer.address}}'
};
});
})();
这不会写入任何浏览器控制台内容
但如果我将信号器代码移出它编写的指令
(function(){
"use strict";
var hub = $.connection.realtimeFult;
$.connection.hub.url = "http://localhost:39858/signalr";
$.connection.hub.start();
hub.client.faultOccured = function (location) {
console.log(location);
};
angular.module('docsSimpleDirective', [])
.controller('Controller', ['$scope', function($scope) {
}])
.directive('myCustomer', function() {
return {
template: 'Name: {{customer.name}} Address: {{customer.address}}'
};
});
})();
此代码编写浏览器控制台日志
这个有趣问题的原因是什么?在第一个示例中,我看到您在控制器内部使用了
信号机
,我是否遗漏了什么?是的,第一个示例在控制器中,第二个示例在控制器外部。。。。但是如果我把信号器代码移出它写的指令代码>。hmm当我在hub.client.fault发生后调用$.connection.hub.start()
时,它在控制器中工作。我使用的是Signalr2.2.2版本。也许有些事情改变了。