Hi Gomtesh,
Query : How can i do syncfusion modal dialog using angularjs with diffrent controllers
You can use the modal dialog to update the form values. We have prepared a sample to showcase our modal dialog and updating its content through Angular. The sample can be downloaded from the following location.
Sample Location : Modal Dialog
In the above sample, we have used two different controllers. On clicking the “submit” button present inside the Modal Dialog, you can see that we call a service to expose its value in both the controllers. Please let us know whether the provided sample helps to you or not. If we have misunderstood your requirement, please get back to use with more information about your requirement or revert back the provided sample based on your application to showcase your requirement.
Regards,
Hi Gomtesh,
Thanks for the update,
We have analyzed your query (“open the dialog without id”).We can use the class name also to access the dialog. Please refer the below code snippet
[script] obj=$(".e-dialog.e-js").data("ejDialog"); if(obj) obj.open(); |
We have modified the sample based on your requirement. Please get the sample from below location
Sample
Also, we have defined the dialog control’s element in another controller. So to communicate between the two separate controllers we have used $broadcast service. The broadcast service accessed using ‘$rootScope’. Please refer the below code snippet.
myApp.controller('basic_controller', function ($rootScope) { $rootScope.call_otherctrl = function () { $rootScope.$broadcast('Dialog_open'); } }); |
modal dialog not close when click on submit
We can close the dialog in ng-click(submit button) event using our existing method “close” in dialog control. Please refer the below code snippet.
$scope.press = function (user) { obj=$(".e-dialog.e-js").data("ejDialog"); if (obj) obj.close(); } |
Please check with the modified sample and let us know if you have further queries.
Regards,
Hi Gomtesh,
Thanks for the update.
We have analyzed your query (modal code in same file where modal is called but i wants modal code in separate html file). We can achieve your requirement using “ng-include” directive (ng-include directive used to insert the html content inside another html content). Please find the sample from below location
In this sample, we have maintained the model dialog controller in separate html file (“basicdialog.html”). Once the content is loaded successfully, we have created the dialog control in ‘$includeContentLoaded’ event. ‘$includeContentLoaded’ is an event which is emitted every time the ng-include is updated (content loaded). We can listen this event from other controller also. Also to communicate between the two different controllers(where one controller is included using ng-include directive), we have to define the $broadcast service after the content is loaded(i.e. within the ‘$includeContentLoaded’) .
Please refer the below code snippet.
[script]
$ rootScope.$on('$includeContentLoaded', function () { $("#basicDialog").ejDialog({ width: 550, height: 300, showOnInit: false, enableModal: true, title: "User Information"
}); $rootScope.call_otherctrl = function () { $rootScope.$broadcast('Dialog_open');
} }); |
Please check with the given sample and let us know if you have further queries.
Regards,
Sasikala Nagarajan
Hi Gomtesh,
Thanks for the update,
Query 1: I have auto increment that ID when i open dialog i.e. in Leave ID text box i have to get next number
We can achieve your requirement by maintaining the scope variable in main controller and then increment its value on button click event (event that triggers the dialog to open) whenever we open the dialog.
Please refer the below code snippet.
[html] <input type="text" id="LeaveID" ng-model="user" /> |
[_script] var myApp = angular.module('DialogCtrl', ['ejangular']); myApp.controller('basic_controller', ['$scope', function ($scope) { $scope.user = ""; $scope.count = 0; $scope.dialogopen = function (user) { $("#basicDialog").ejDialog("open"); $scope.count++; } }]); |
Query 2: Next number that should also work when i refresh the page
To maintain this textbox value even after the refreshing, we have to get and put the specified value (Count) from browser cookies using $cookies service in angular js. But if cleared the cookie or if we run the page in another browser then this valuewill not be maintained properly or the value will be lost. So to maintain the count value all the time, please use this Leave id as one ofthe fieldin your database.
Query 3: I have to store each leave information i.e json string to local storage in single array
We can convert the form fields values (json string) into array using jquery method serializeArray().
Please refer the below link to know more about serializeArray.
https://api.jquery.com/serializeArray/
Please let us know if you have further queries,
Regards,
Sasikala Nagarajan
Hi Gomtesh,
Thanks for the update,
Query 1: I click on button for dialog open it will opens the dialog but it contains previous entered values.
We have analyzed your query. To achieve this requirement, we need to empty the form fields manually before we open the dialog.
Please refer the below code snippet
app.controller('Dialog_ctrl', function ($scope, $rootScope, $localStorage) { $scope.$on('Dialog_open', function (event) { $scope.obj = $(".e-dialog.e-js").data("ejDialog"); if ($scope.obj) $scope.leave.todatevalue = ""; $scope.d1 = ""; $scope.leave.leave_days = ""; $scope.obj.open(); }); $scope.press = function (leave) { if ($scope.obj) $scope.obj.close(); }; }); |
Query 2: i have taken in modal datepicker and other controls but datepicker works as simple textbox it will not render datepicker
We suspect that the reported issue may be caused due to missing of any dependent script file. Also Datepicker control have localization support so we have to refer the “jquery.globalize” file to render the Datepicker control.
Please refer below code snippet to know the dependent script file.
<!--Dependent Scripts for Essential JavaScript Components--> <script src="Scripts/jquery-1.10.2.min.js"></script> <script src="Scripts/jquery.easing.1.3.js"></script> <!—Please include below two scripts for Essential JavaScript Components which have localization support--> <script src="Scripts/jquery.globalize.min.js"></script> <script src="Scripts/jquery.globalize.cultures.min.js"></script> <!--Dependent Scripts for all componets--> <script src="Scripts/ej/ej.web.all.min.js"></script> |
Also, please make use of our online documentation, to create our components.
http://help.syncfusion.com/web - This link is the common user guide for getting started with JavaScript, ASP.NET MVC and ASP.NET components
Please let us know if you have further queries,
Regards,
Sasikala Nagarajan
$scope.d1 = "";
$scope.leave.leave_days = "";Hi Gomtesh,
Sorry for the inconvenience caused,
We have analyzed your query. We are unable to reproduce the reported issues(when i switch to another navigation tab i.e. in other HTML web page or other controller then that modal contain previous values and not render the date-picker it is simple textbox) in our side.
Please provide more details on your query or else can you please reproduce the issue in the sample (which is given by us in previous updates) and revert us the modified sample and that will be helpful for us to provide the prompt solution.
Please let us know if you have further queries,
Regards,
Sasikala Nagarajan
Hi Gomtesh,
Thank you for sharing code example.
As per our support guidelines; we offer only limited and basic support through forums widely.
Since your request for “Syncfusion modal dialog with datepicker,textboxes using angular js with different controllers” seems to be issue fix which is beyond our support limit consigned for a forum.
Hence, we are requesting you to create an incident through Direct trac. If you face any issues availing support through Direct Trac, please contact salessupport@syncfusion.com for further assistance.
You can login to the Direct-Trac and create an incident in the following link:
As always we are happy to assist you.
Regards,
Saranya
<div id="Grid" ej-grid e-datasource="data">
in above code all information to form a grid passing through $scope.data = dataforgrid;