javascript - How to pass controller into modal view -
i've been on unhealthy length of time. initially, modal.open darkened screen without dialog box coming up. used windowtemplateurl override templeteurl , showed. nothing controller passes through; neither cancel() function nor data api seem work. possible solution welcome.
(function() { angular .module('loc8rapp') .controller('locationdetailctrl', locationdetailctrl); locationdetailctrl.$inject = ['$routeparams', '$uibmodal', 'loc8rdata']; function locationdetailctrl($routeparams, $uibmodal, loc8rdata) { var vm = this; vm.locationid = $routeparams.locationid; loc8rdata.locationbyid(vm.locationid) .success(function(data) { vm.data = { location: data } vm.pageheader = { title: vm.data.location.name }; }) .error(function(e) { console.log(e); }); vm.popupreviewform = function() { var modalinstance = $uibmodal.open({ templateurl: "/reviewmodal/reviewmodal.view.html", backdrop: true, //windowclass: 'show', windowtemplateurl: "/reviewmodal/reviewmodal.view.html", controller: 'reviewmodalctrl vm', //size: 'sm', resolve: { locationdata: function() { return { locationid: vm.locationid, locationname: vm.data.location.name }; } } }); }; } })(); //modal controller (function() { angular .module('loc8rapp') .controller('reviewmodalctrl', reviewmodalctrl); reviewmodalctrl.$inject = ['$uibmodalinstance', 'locationdata']; function reviewmodalctrl($uibmodalinstance, locationdata) { var vm = this; vm.locationdata = locationdata //create vm.modal.cancel() method , use call $modalinstance.dismiss method vm.modal = { cancel: function() { $uibmodalinstance.dismiss('cancel'); } }; } })();
<div class="container modal-content"> <form id="addreview" name="addreview" role="form" class="form-horizontal"> <div class="modal-header"> <button type="button" ng-click="vm.modal.cancel()" class="close"><span aria-hidden="true">x</span><span class="sr-only">close</span></button> <h4 id="mymodallabel" class="modal-title">add review {{ vm.locationdata.locationname }}</h4> </div> <div class="modal-body"> <div class="form-group"> <label for="name" class="col-xs-2 col-sm-2 control-label">name</label> <div class="col-xs-10 col-sm-10"> <input id="name" name="name" required="required" ng-model="vm.formdata.name" class="form-control" /> </div> </div> <div class="form-group"> <label for="rating" class="col-xs-10 col-sm-2 control-label">rating</label> <div class="col-xs-12 col-sm-2"> <select id="rating" name="rating" ng-model="vm.formdata.rating"> <option>5</option> <option>4</option> <option>3</option> <option>2</option> <option>1</option> </select> </div> </div> <div class="form-group"> <label for="review" class="col-sm-2 control-label">review</label> <div class="col-sm-10"> <textarea id="review" name="review" rows="5" required="required" ng-model="vm.formdata.reviewtext" class="form-control"></textarea> </div> </div> </div> <div class="modal-footer"> <button ng-click="cancel()" type="button" class="btn btn-default">cancel</button> <button type="submit" class="btn btn-primary">submit</button> </div> </form> </div>
i use this, in rootcontroller of app make this:
$rootscope.openmsgmodal = function (modalsettings) { var defaultsettings = { title: "title", msg: "message", icon: "fa-info-circle", iconcolor: "#c83637", clickaction: "ok", iscancelvisible: false, templateurl: 'views/templates/popups/alertmessage.html', controller: 'modalalertcontroller', translations: { confirmbutton: "common.button_confirm", cancelbutton: "common.button_cancel" } } angular.extend(defaultsettings, modalsettings); var modalinstance = $uibmodal.open({ templateurl: defaultsettings.templateurl, controller: defaultsettings.controller, size: 'md', resolve: { modalsettings: function () { return defaultsettings; } } }); return modalinstance; }; }
...and then, need use modal have this:
var modalinstance = $uibmodal.open( { animation: true, templateurl: 'views/templates/popups/alertmessage.html', controller: 'modalalertcontroller', resolve: { modalsettings: function() { angular.extend(defaultsettings, modalsettings); return defaultsettings; } } });
wiki
Comments
Post a Comment