我尝试使用Angular实现SignalR,所以我遵循这个tutorial。在我的app.js中我有这样的东西:
var app = angular.module('portalTransporte', ['common.core', 'common.ui'])
.config(config)
.run(run)
$(function () {
$.connection.hub.logging = true;
$.connection.hub.start();
});
$.connection.hub.error(function (err) {
console.log('An error occurred: ' + err);
});
angular.module('portalTransporte')
.value('notification', $.connection.notification)
.value('toastr', toastr);
/* Setup global settings */
app.factory('settings', ['$rootScope', function ($rootScope) {
// supported languages
var settings = {
layout: {
pageSidebarClosed: false, // sidebar menu state
pageContentWhite: true, // set page content layout
pageBodySolid: false, // solid body color state
pageAutoScrollOnLoad: 1000 // auto scroll to top on page load
},
assetsPath: '../Metronic',
globalPath: '../Metronic/global',
layoutPath: '../Metronic/layouts/layout',
origen: 'Web',
version: '0.1W'
};
$rootScope.settings = settings;
return settings;
}]);
config.$inject = ['$stateProvider', '$urlRouterProvider', 'cfpLoadingBarProvider'];
function config($stateProvider, $urlRouterProvider, cfpLoadingBarProvider) {
//console.log("config");
cfpLoadingBarProvider.includeSpinner = false;
cfpLoadingBarProvider.includeBar = true;
cfpLoadingBarProvider.loadingBarTemplate = '<div id="loading-bar"><div class="bar"><div class="peg"></div></div></div>';
//$urlRouterProvider.otherwise("/dashboard.html");
$urlRouterProvider.otherwise(function ($injector, $location) {
var $state = $injector.get("$state");
$state.go("root.dashboard");
});
$stateProvider
.state('root.cliente_viaje_solicitud_detalle', {
url: "viajes_c/solicitud/detalle.html",
templateUrl: "../SPA/viajes_clientes/solicituddetalleCliente.html",
controller: "solicituddetalleClienteCtrl",
authenticate: true,
data: { pageTitle: 'FLETERISTAS - DETALLE DE SOLICITUD' },
params: {
modo: "nuevo",
viajeId: null
}
在JS中我调用这样的函数:
solicituddetalleClienteCtrl.$inject = ['$scope', 'apiService', 'notificationService', '$rootScope', '$location', '$http', '$stateParams', '$state', 'limitToFilter', 'notification', 'toastr'];
function solicituddetalleClienteCtrl($scope, apiService, notificationService, $rootScope, $location, $http, $stateParams, $state, limitToFilter, notification, toastr) {
$scope.guardar = function () {
var inputval = "NewvTrip added";
notification.server.pushNotification(inputval);
$scope.newMessage = "";
};
notification.client.response = function onNewMessage(message) {
displayMessage(message);
$scope.$apply();
};
function displayMessage(message) {
toastr.success(message); //To nofiy as fadin and fadout
}
我将它变成了chrome,当它到达这一行notification.server.pushNotification(inputval);
时,它总是抛弃我
SignalR:必须先启动连接才能发送数据。呼叫 .start()之前.send()
有人可以帮忙吗?问候 。我可以通过Skype或Chrome遥控器分享我的桌面
当我呼叫集线器时,我没有看到任何错误。但我确定问题是app.js,我看到相关的问题,但我找不到解决方案。