0

I am updating one scope variable from an ngDialog popup.

View :

<input type="radio"  name="file_selector" value={{file.id}} ng-model="selected_file.id" ></input>
 

controller.js

 $scope.selected_file   = {'id' : '22'};

If I have the above view in non-popup HTML, ng-model updates and view changes.

ngDialog :

$scope.openUploadPopup = function() {
  ngDialog.open({
   template: 'partials/upload.html',
   controller: 'notificationController',
   className: 'ngdialog-theme-default',
   scope: $scope
   });
} 

Edit : Plunker : http://plnkr.co/edit/8TUtwixKwvVaycDuvHd9?p=preview

Rakesh
  • 5,793
  • 8
  • 36
  • 37
  • Can you pls create a plunker? – ramamoorthy_villi Apr 06 '15 at 06:27
  • 1
    Plunker : http://plnkr.co/edit/8TUtwixKwvVaycDuvHd9?p=preview – Rakesh Apr 06 '15 at 07:53
  • Your plunker doesn't work. Is that the issue? – Re Captcha Apr 06 '15 at 08:08
  • Try now, my plunk wasn't update/ modified. I have frozen it. If you select on the radio button ( Click to change value ) the value updates. The click link creates a ngDialog containing another radio button ( Click to change value - 2 ), update is not happening from here, even though scope is being set. – Rakesh Apr 06 '15 at 08:57

1 Answers1

2

i changed your files, works for me.

HTML :

<html>

  <head>
    <script src="https://code.angularjs.org/1.4.0-beta.6/angular.js"></script>
    <script  src="http://likeastore.github.io/ngDialog/js/ngDialog.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="notifications_web_portal" ng-controller="notificationController">
    <div ng-view>
    <h1>Hello Plunker!</h1>
      <span> File selected : {{selected_file.id}}</span>
      <a href='javascript:void(0)' ng-click="openUploadPopup()" >Open Dialog</a>
      </div>
  </body>

</html>

JS :

// Code goes here
var notifApp = angular.module('notifications_web_portal', ['ngDialog']); 

notifApp.controller('notificationController', function($scope, $rootScope, $window , ngDialog) {
  $scope.openUploadPopup = function() {

    ngDialog.open({
      template: '<input type="radio"  name="file_selector" value="87" ng-model="selected_file.id" ></input>',
      controller: 'notificationController',
      plain: true,
      className: 'ngdialog-theme-default',
      scope: $scope
      });
  }
});

Changes done :

  • plain: true added
  • notifApp.controller('notificationController',......
ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40
  • In actual code I can't use plain: true as code is big enough and can't be send as a string for maintainability reasons. – Rakesh Apr 06 '15 at 09:05
  • you should use plain: true, otherwise create a file externalTemplate.html, add like this template: 'externalTemplate.html', – ramamoorthy_villi Apr 06 '15 at 09:21
  • Yep, any idea why I need to declare "$scope.selected_file = {'id' : ''};" inside function and not anywhere in controller scope .. say first line in controller. It doesn't work in the latter case. – Rakesh Apr 06 '15 at 10:48