Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
信号器客户端未填充angularjs指令_Angularjs_Angularjs Directive_Signals - Fatal编程技术网

信号器客户端未填充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

我有一个angularjs指令将使用信号器

(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版本。也许有些事情改变了。