javascript - Is there some way I can pass a reference to an Angular model to a scope function? -
i have several canvas
areas in web app capture peoples' signatures, on official documentation. busy trying develop popup, provide larger area user sign on, on smaller devices. signature areas this:
<canvas width="400" height="200" ng-signature ng-model="party1.signaturebase64"></canvas> <a href="" ng-click="getsignaturemodal(party1.signaturebase64)">show signature pad</a>
then have following function on view scope pops modal gather signature data, javascript's "by value" passing, stuck how return value function model.
$scope.getsignaturemodal = function (signaturebase64) { var modalinstance = $modal.open({ templateurl: 'signaturewindow.html', controller: 'signaturemodalcontroller', size: 'lg', resolve: { base64: function () { return signaturebase64; } } }); modalinstance.result.then(function (base64) { signaturebase64 = base64; return base64; }, function () { alert('canceled'); }); };
i update ng-click to:
ng-click="party1.signaturebase64=getsignaturemodal(party1.signaturebase64)"
but seems getting bit unwieldy. or best way?
i injecting $rootscope , $broadcast
ing modal.
retrofit controller receive model payload on message , decouple modal implementation. while back, created fiddle uses $rootscope
message broker. i'm not sure have enough information of specific domain know sure performant need, can check out @ $rootscope message broker
view
<div ng-controller="messenger"> <input ng-model="message" style="width:100px"> <input ng-model="target" style="width:87px" > <button ng-click="handleclick(message,target);">send message</button> </div> <div ng-controller="controllerone"> <input ng-model="message" > </div> <div ng-controller="controllertwo"> <input ng-model="message" > </div>
selected angular stuffs
var mymodule = angular.module('messageorientedmodule', []); mymodule.factory('messagingservice', function($rootscope) { var service = {}; service.notify = function(message, recipient, type){ var payload = {}; object.defineproperty(payload,"recipient",{value:recipient}); object.defineproperty(payload,"body",{value:message}); $rootscope.$broadcast(type,payload); }; return service; }); function messenger($scope, messagingservice) { $scope.handleclick = function(message,target) { messagingservice.broadcastspecific(message,target); }; $scope.$on('message.broadcast', function(event, message) { $scope.message = message.body + ' [sent]'; });} function controllerone($scope) { $scope.$on('message.broadcast', function(event, data) { if(data.recipient != "ctrl1") { $scope.message = '123 not it!'; } else { $scope.message = '[ctrl1][received]:' + data.body; } }); } function controllertwo($scope) { $scope.$on('message.broadcast', function(event,data) { if(data.recipient != "ctrl2") { $scope.message = '123 not it!'; } else { $scope.message = '[ctrl2][received]:' + data.body; } }); }
Comments
Post a Comment