Angular function constructor in Controller

Posted by BigHeadCreations on Stack Overflow See other posts from Stack Overflow or by BigHeadCreations
Published on 2014-08-19T02:58:48Z Indexed on 2014/08/19 4:20 UTC
Read the original article Hit count: 187

Filed under:
|

In normal JS I can do this:

function Droppable() {
    this.relevant = true;
    this.uuid = generateUUID();
};

var generateUUID = function() {
   return '12345';
}


console.log(new Droppable); // returns Droppable {relevant: true, uuid: "12345"}

But in Angular I have this:

angular.module('myApp').controller('MyCtrl', ['$scope', function($scope) {

    function Droppable() {
        this.relevant = true;
        this.uuid = generateUUID();
    }

    var generateUUID = function() {
        return '12345';
    }

    // initalize droppable areas
    $scope.region1 = [new Droppable];
    $scope.region2 = [new Droppable];
    $scope.region3 = [new Droppable];

}]);

I am trying to make 3 droppable areas all with a UUID.

But when I do this I get 'undefined is not a function' referring to the line this.uuid = generateUUID(); in function Droppable() {...}

Why is that?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about angularjs