AngularJS - modal inserts template with radiobutton options

2

I have a button that opens a modal, where words separated by commas will be typed which will become the radiobutton options on the main page. When saving the modal you must insert an HTML template with this embedded data.

Follows plunker

    
asked by anonymous 04.11.2016 / 11:47

1 answer

2

This Plunker contains the following fixes for your modal operation:

The ui.bootstrap script files were imported;

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.2.0/ui-bootstrap.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.2.0/ui-bootstrap-tpls.min.js" type="text/javascript"></script>

Added library import to module :

var app = angular.module('plunker', ['ui.bootstrap']);

Added service for passing variables:

angular
  .module('plunker')
  .factory('serviceModal', serviceModal);

serviceModal.$inject = [];

function serviceModal() {
  var opcoes = "";

  return {
    setOpcoes: setOpcoes,
    getOpcoes: getOpcoes
  }

  function setOpcoes(novasOpcoes) {
    this.opcoes = novasOpcoes;
  }

  function getOpcoes() {
    if (this.opcoes === undefined) {
      this.opcoes = "";
    }

    return this.opcoes;
  }
}

Added dependency injections in controller master to $uibModal , $timeout and serviceModal :

.controller('MainCtrl', function($scope, $uibModal, $timeout, serviceModal)

Using service to pass variables:

serviceModal.setOpcoes($scope.data.opcoes);

and

$scope.verificarOpcoes = function() {
  var op = serviceModal.getOpcoes();

  if (op !== undefined && op !== "") {
    return op.split(",");
  }
}
    
04.11.2016 / 12:23