Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass dynamic data to template when createDialog used

Tags:

angularjs

my UI has two buttons one for Create and another for Edit.

  • Create -should show empty fields pop-up
  • Edit - Existed data should be prepopulate to pop-up
  • I used same pop-up for create and Edit actions

    create_quick_link.html
    <div class="row-fluid">
        <div class="form-group">
          <label class="control-label col-sm-4">
             <font class="pull-right">Name</font>
              <span class="red pull-right">*</span>
          </label>
          <input placeholder="Name" type="text" ng-model="quickLink.name">
        </div>
        <div class="form-group">
           <label class="control-label col-sm-4">
             <font class="pull-right">URL</font>
             <span class="red pull-right">*</span>
           </label>
           <input placeholder="URL" type="text"  ng-model="quickLink.url">
        </div>
     </div>
    
    
    $scope.editQuickLink = function (editableQuickLinkdata) {
    
            $scope.quickLink.name = editableQuickLinkdata.quickLinkName;
            $scope.quickLink.url = editableQuickLinkdata.quickLinkUrl;
            createDialog({
                templateUrl: '/app/ajs/followup/app/views/create_quick_link.html',
                title: 'Edit Quick Link',
                controller: 'FollowupssettingsCtrl',
                footerTemplate: '<button class="btn btn-primary" ng-click="updateQuickLink(quickLink)">Update</button>'
            });
    
        }
    

I want to set the editableQuickLinkdata to quickLink

My data is not populated .am i doing wrong ?

like image 356
Arepalli Praveenkumar Avatar asked Sep 30 '22 12:09

Arepalli Praveenkumar


1 Answers

You can do it as follows:

$scope.editQuickLink = function (editableQuickLinkdata) {
    createDialog({
        templateUrl: '/app/ajs/followup/app/views/create_quick_link.html',
        title: 'Edit Quick Link',
        controller: 'EditCtrl',
        footerTemplate: '<button class="btn btn-primary" ng-click="updateQuickLink(quickLink)">Update</button>'
    },{myOldData: editableQuickLinkdata});

}

Then in the EditCtrl, in addition to $scope, you will get myOldData as an argument :

angular.module('MyApp').controller('EditCtrl', ['$scope', 'myOldData',
function($scope, myOldData) {
 // Do stuff 
}]);
like image 151
Arepalli Praveenkumar Avatar answered Nov 15 '22 10:11

Arepalli Praveenkumar