angularjs - Angular bootstrap modal how to call service from ok function of the modal? -


i have implemented angular bootstrap modal. below angular code it

var modaldemoctrl = function ($scope, $modal, $log) {    $scope.items = ['item1', 'item2', 'item3'];    $scope.open = function (size) {      var modalinstance = $modal.open({       templateurl: 'mymodalcontent.html',       controller: modalinstancectrl,       size: size,       resolve: {         items: function () {           return $scope.items;         }       }     });      modalinstance.result.then(function (selecteditem) {       $scope.selected = selecteditem;     }, function () {       $log.info('modal dismissed at: ' + new date());     });   }; };  // please note $modalinstance represents modal window (instance) dependency. // not same $modal service used above.  var modalinstancectrl = function ($scope, $modalinstance, items) {    $scope.items = items;   $scope.selected = {     item: $scope.items[0]   };    $scope.ok = function () {     $modalinstance.close($scope.selected.item);   };    $scope.cancel = function () {     $modalinstance.dismiss('cancel');   }; }; 

this works fine.

my question how use services in modal's controller ? in ok function want make service call , save details , use success , error callback.

i not sure how go doing this.

you inject dependencies through controller constructor, i.e.:

var modalinstancectrl = function ($scope, $modalinstance, items, myservice) {  $scope.ok = function () {     myservice.dosomething();     $modalinstance.close($scope.selected.item); }; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -