0

I can't get $compile to work correctly inside my directive. I am trying to insert html to element with ng-bind directive inside. I am passing variable from selector service to ng-bind.

Binding does not work when I display my html. Instead I get empty element. Html after compiling looks like this :

<div class = "song_info ng-binding ng-scope" data-ng-bind = "year"></div>

this is the directive that i am using :

.directive("sortableQueue", ["$compile", "selector", function($compile, selector){
    return{
        scope : {},
        link : function(scope, element){
            element.sortable({
                stop : function(event, ui){

                    //get helper html
                    var song_element = $(ui.item);

                    //logs correct value
                    console.log(selector.getValue());

                    var html = "<div class = 'song_info' data-ng-bind = '" + selector.getValue() + "'></div>";

                    var content = $compile(html)(scope);

                    song_element.html(content);
                }
            });
        }
    };
}])

Does someone know what mistake am I making here? Any help is appreciated.

2 Answers 2

1

All works fine.

Answer is here:

data-ng-bind = "year"

Angular tries to find year variable. Of course it cant find it and display nothing. You have to create variable in your scope, from where it will take data.

Sign up to request clarification or add additional context in comments.

Comments

0

You use an isolated scope, I suppose your variable year is defined in parent scope. Try to replace :

scope : {},

by

scope: true,

1 Comment

there is no variable year. year is value of variable that is stored in service selector. I am trying to bind variable from that service to html. I should not need any other scope in this directive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.