我有一个将使用SignalR的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}}'
};
});
})();
这不会写任何浏览器控制台。
但是如果我将signalR代码移出它写的指令。
(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}}'
};
});
})();
此代码编写浏览器控制台日志。
这个有趣问题的原因是什么?