Simple example of using ngDialog in angularjs to open the popups.
Step 1: You need ngDialog css and js libraries. You can download these from here:
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/css/ngDialog-theme-default.css
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/css/ngDialog.css
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/js/ngDialog.js
Step 2: Inject "ngDialog" in the app.js file.
var myApp = angular.module("myApp", ["ngRoute", "ngStorage", 'requestUtils',"ngDialog"]);
Step 3: Now inject that ngDialog in your angular controller where you want to consume its methods.
myApp.controller("itemCtrl", ["$scope", "$state", "ngDialog", function ($scope, $state, ngDialog) {
$scope.vm = this;
//This function is for render the html in dialog box.
$scope.vm.openDialog = function () {
var newScope = $scope.$new();
ngDialog.open({ template: 'templateId', scope: newScope });
};
//Following function is used for open the html page in the dialog.
$scope.vm.openHtmlPagePopup = function () {
ngDialog.open({ template: '/App/test.html', controller: 'testCtrl', scope: $scope, className: 'ngdialog-theme-default' });
}]);
Html:
<script type="text/ng-template" id="templateId">
<h3>Some content</h3>
</script>
Step 1: You need ngDialog css and js libraries. You can download these from here:
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/css/ngDialog-theme-default.css
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/css/ngDialog.css
https://cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.6.2/js/ngDialog.js
Step 2: Inject "ngDialog" in the app.js file.
var myApp = angular.module("myApp", ["ngRoute", "ngStorage", 'requestUtils',"ngDialog"]);
Step 3: Now inject that ngDialog in your angular controller where you want to consume its methods.
myApp.controller("itemCtrl", ["$scope", "$state", "ngDialog", function ($scope, $state, ngDialog) {
$scope.vm = this;
//This function is for render the html in dialog box.
$scope.vm.openDialog = function () {
var newScope = $scope.$new();
ngDialog.open({ template: 'templateId', scope: newScope });
};
//Following function is used for open the html page in the dialog.
$scope.vm.openHtmlPagePopup = function () {
ngDialog.open({ template: '/App/test.html', controller: 'testCtrl', scope: $scope, className: 'ngdialog-theme-default' });
}]);
Html:
<script type="text/ng-template" id="templateId">
<h3>Some content</h3>
</script>
In this post I have added "var newScope = $scope.$new();". This pass the scope of current controller to the html that rendered in the dialog. With the help of this any changes in the model will reflect in the controller.
ReplyDelete