angularjs - Pass a promiss to the resolve-Object of an ui.angular Modal-Dialog -



angularjs - Pass a promiss to the resolve-Object of an ui.angular Modal-Dialog -

i have big problem. have problems modal dialog of ui.bootstrap. do. have dialog adding rocker(here called clicker) database. when every thing okay dialog gets closed, if not show error-message. handled in controller of modal-dialog.

because of usage of jwt socketio had create socketio mill returns ppromiss. able utilize socketio-instance in modal-controller have set in resolve-object of $modal.

the problem is, every time set socketio-eventhandler in modal-controller, browser shows me message controller-method undefined. (no dialog showing, error-message in console)

here code. hope can help me! have no thought how solve problem.

socketmodule.js

socketmodule socketio-factory returns promise. everywhere else in code works. modal dialog has problem approach.

var socketiomodule = angular.module('socketiomodule', []); socketiomodule.factory('socket', ['$q', '$rootscope', 'socketfactory', '$timeout', '$location', 'authhostservice', function($q, $rootscope, socketfactory, $timeout, $location, authhostservice) { // create promise instance var socket = $q.defer(); // hear authenticated event emitted on rootscope of // angular app. 1 time event fired, create socket , resolve // promise. $rootscope.$on('authenticated', function() { console.log('received broadcast'); var protocol = $location.protocol(); var host = $location.host(); var port = $location.port(); var baseurl = protocol+'://'+host+':'+port; // resolve in digest cycle $timeout(function() { // create socket var newsocket = (function() { homecoming socketfactory({ iosocket: io.connect(baseurl, { 'forcenew': true, 'query': 'token=' + authhostservice.gettoken() }) }) })(); // resolve promise socket.resolve(newsocket); }); }); // homecoming promise homecoming socket.promise; } ]);

clickermodule.js

'use strict'; var clickermodule = angular.module('clickermodule', ['nganimate','ui.bootstrap.modal', 'socketiomodule']); clickermodule.controller('clickermanagerctrl', ['$scope', '$location', '$modal', 'socket', function($scope, $location, $modal, socket) { ... $scope.openaddclickermodal = function() { //get's next possible clickerid database socket.then(function(socket) { socket.emit('clicker:getnextclickerid', {}); }); var modalinstance = $modal.open({ templateurl: 'partial-views/modal_dialogs/addclickermodal.html', controller: addclickermodalctrl, size: 'lg', backdrop: 'static', keyboard: true, resolve: { socket: function(){ homecoming socket; } } }); }; ... }]); function addclickermodalctrl($scope, $modalinstance, socket) { $scope.nextclickerid = 'no id'; $scope.input = {}; $scope.errormsg = { hide: true }; //receives next possible id socket.then(function (socket) { socket.on('clicker:getnextclickerid', function (msgobj) { $scope.nextclickerid = msgobj.nextclickerid; }); }); $scope.addclicker = function () { if (typeof($scope.input.enoceanuid) !== '' || $scope.input.enoceanuid !== null) { socket.then(function (socket) { socket.emit('clicker:addclicker', { 'enoceanuid': $scope.input.enoceanuid, 'clickername': $scope.input.clickername }); }); } }; $scope.cancel = function () { $modalinstance.dismiss('cancel'); }; socket.then(function(socket){ socket.on('clicker:addclicker', function(msgobj){ console.log(json.stringify(msgobj)); if(msgobj.success){ $modalinstance.dismiss('cancel'); } else { $scope.errormsg.hide = false; $scope.errormsg.msg = msgobj.error.errormsg; } }); }); }

angularjs angular-ui angular-ui-bootstrap

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -