John Fu
John Fu

Reputation: 1832

Injected factory undefined in compiled directive

I have a problem with my compiled directive where an injected factory is returning undefined. I have checked spellings already and it all checks out.

I am inserting a directive dynamically on click by using

var elDetails = $compile('<profiles></profiles>')($scope);

My profiles

app.directive('profiles', function() {
    return {
        restrict: 'E',
        replace: true,
        scope:{},
        templateUrl: '/Redesign/Scripts/App/Blocks/profiles.html',
        link: function(scope, elem, attrs) {

        },
        controller: function($scope, Profiles) {
            $scope.profiles = new Profiles();
        }
    }
});

I also have a factory called Profiles which looks like this:

app.factory('Profiles', function($http) {
    var Profiles = function() {
        this.items = [];
        this.busy = false;
        this.after = 0;
        this.orderBy = 'CreatedDate,CompletedDate';
        this.filter = '';
    };

What am I doing wrong? Thanks.

John.

Upvotes: 0

Views: 200

Answers (1)

John Fu
John Fu

Reputation: 1832

That was stupid. I forgot to return my factory.

app.factory('Profiles', function($http) {
    var Profiles = function() {
        this.items = [];
        this.busy = false;
        this.after = 0;
        this.orderBy = 'CreatedDate,CompletedDate';
        this.filter = '';
    };

    return Profiles;
});

Upvotes: 2

Related Questions