user1376704
user1376704

Reputation:

How to get pop-up with ngDialog?

I couldn't get this ngDialog module working with AngularJs so looking for some hint where I went wrong.

My Json file named abc.json

[{"id":
  [
      {
          "value":"text_id",
          "desc":"Text id"
      },
      {
          "value":"group_id",
          "desc":"Group id"
      },
  ]
}]

Angular Controller

'use strict';

angular.module('mine.controllers', [])
        .controller('myController', ['$scope', '$sce', '$http',  function($scope, $sce, $http, ngDialog) {
            $http.get('abc.json')
            .success(function(data) {
              $scope.ids = data;
            });
            $scope.openPlain = function (message) {
              ngDialog.open(message);
            };
          }]);

And finally the HTML

<body ng-app="mine">
    <table ng-controller="myController">
        <tr ng-repeat="datas in ids">
            <td>
                <span ng-repeat="iden in datas.id">
                    <a href="" ng-click='openPlain("{{ iden.desc }}")'>{{ iden.value }}</a>, 
                </span>
            </td>
        </tr>
    </table> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.2.3/js/ngDialog.min.js"></script>
</body>

Here is the JsFiddle, but I couldn't make it work with JsFiddle either, some different error.

In my local machine I don't get any error when the DOM loads and the value are displayed correctly from the JSON file. However when I click the link, I get this error:

TypeError: Cannot call method 'open' of undefined

So I am guessing the ngDialog is not loaded or something else.

Upvotes: 2

Views: 20967

Answers (2)

HydrUra
HydrUra

Reputation: 1516

You had a problem of injection and you have to call the CSS files in your HTML. Controller

.controller('myController', ['$scope', '$sce', '$http', 'ngDialog', 
                             function($scope, $sce, $http, ngDialog) {

HTML:

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.2.3/css/ngDialog.css" />

Then it works !

Upvotes: 1

chubbsondubs
chubbsondubs

Reputation: 38676

You didn't inject ngDialog into your controller properly:

This line:

.controller('myController', ['$scope', '$sce', '$http',  
                              function($scope, $sce, $http, ngDialog) {

This should be:

.controller('myController', ['$scope', '$sce', '$http', 'ngDialog', 
                             function($scope, $sce, $http, ngDialog) {

Here is your fiddle working. You didn't specify the template to use to layout the dialog. Anyway this will get you a bit further along.

http://jsfiddle.net/ys01yoLk/5/

Upvotes: 2

Related Questions