BagrijRoman
BagrijRoman

Reputation: 249

Passing data from ng-Dialog html to controller

have some trouble with ng-Dialog. When i note ngDialog controller option, it works. I can get $scope.descriptionText value from

<p>Description:</p>
    <textarea ng-model="descriptionText"></textarea>

now i call dialog witout parametr controller

 ngDialog.open({
          template: 'views/pages/timesheet/template/newEventTemplate.html',
          //controller:'newEventDialogCtrl',
          scope: $scope,
    ...

and this value $scope.descriptionText is undefined.

Please help me return values of html element to my controler, or to controller scope.

Dialog call code:

    $scope.createNewEventModalWindow = function(args)
    {
      $scope.setNewEventField('start', args.start.value);
      $scope.setNewEventField('end', args.end.value);
      ngDialog.open({
          template: 'views/pages/timesheet/template/newEventTemplate.html',
          //controller:'newEventDialogCtrl',
          scope: $scope,
          className: 'ngdialog-theme-default',
          plain: false,
          showClose: true,
          closeByDocument: true,
          closeByEscape: true,
          appendTo: false,
          disableAnimation: false,
          overlay: false
      }).closePromise.then(function(value)
            {
              console.log('Test msg');
              console.log(value);

              var newEvent = {
                start: $scope.getNewEventField('start'),
                end: $scope.getNewEventField('end'),
                text: $scope.descriptionText,
                userID: getCurrentUserID(),
                projectID: $scope.selectedProject,
                taskID: $scope.selectedTask
              };

              console.log('Event data to server');
              console.log(newEvent);
/*
              TimesheetFactory.createEvent(newEvent)
                .success(function(data) {
                    $scope.events = data;
                    $scope.message('Event created');
                    console.log($scope.events);
                })
                .error(function(data) {
                    console.log('Error: ' + data);
                });
*/
            });
    }

Html template for dialog:

<div class="ngdialog-message">
    <h3>Create Event</h3>
    <p>Project</p>

    <select id='selectProject' ng-model= "selectedProject">
      <option ng-repeat="project in projects" value="{{project.id}}">{{project.name}}</option>
    </select>
    <p>Task</p>
    <select id='selectTask' ng-model="selectedTask">
      <option ng-repeat="task in tasks" value="{{task.id}}">{{task.name}}</option>
    </select>
    <p>Time</p>

    <input type="time" id="eventTime" name="input" ng-model="timeLentgh"/>

    <p>Description:</p>
    <textarea ng-model="descriptionText"></textarea>
</div>
<div class="ngdialog-buttons">
    <button
      type="button"
      class="ngdialog-button ngdialog-button-secondary"
      ng-click="closeThisDialog()"
    >Cancel</button>
    <button
      type="button"
      class="ngdialog-button ngdialog-button-primary"
      ng-click="btnCreateEventClicked()"
    >Create</button>
</div>

Upvotes: 1

Views: 1290

Answers (1)

Valentyn Shybanov
Valentyn Shybanov

Reputation: 19391

You can access dialog's scope this way:

value.$dialog.scope()

Where value - argument you get from closePromise.

In this cope you'll have descriptionText for example.

Plunker to check and play: http://plnkr.co/edit/nTNwAxyL1KGuvKGAeTmy?p=preview

Upvotes: 2

Related Questions