ngDialog not working with 'external' controller

I get this error when the ng-dialog pops-up. Here is the function that pops the dialog :

var dialog = ngDialog.open({
        template: 'public/module/fileManagement/filePopUp.tpl.html',
        scope: $scope,
        controller : 'FileController',
        $event: $event
    });

and here is the controller's code :

var fileModule = angular.module('fileModule', []);
fileModule.controller('FileController', function($scope, ngDialog){
var img = {name:'a',description:'a',type:'d'};
$scope.init = function () {
    $scope.img = img;
}
$scope.init();});

The result in the pop-up is as shown below :

nom: {{img.name}}

Notes :

Upvotes: 2

Views: 8290

Answers (2)

Thanks to runTarm, i realised the difference between the plunker implementation and mine :

I created a module (which was not the main module):

var fileModule = angular.module('fileModule', []);

and added the controller to that module :

fileModule.controller('FileController', function(){...});

runTarm added the controller to the main module so it worked well. See his plunker.

In order for my implementation to work, i needed to inject the 'fileModule' to the main module:

var app = angular.module('app', ['ngRoute', 'ngDialog','fileModule']);

Upvotes: 1

runTarm
runTarm

Reputation: 11547

Try to change this line:

controller : 'public/module/fileManagement/FileController',

to just this:

controller : 'FileController',

Example Plunker: http://plnkr.co/edit/5nWJfHf0k5n2reFqcCDL?p=preview

Hope this helps.

Upvotes: 3

Related Questions