0

I have a Problem with my AngularJS Directive named "showFileBrowser". I want to use Javascript in my Template but it will not be execute in my Browser. Here is my Code:

app.directive("showFileBrowser", function() {
    return {
        restrict: 'E',
        template: '<script>$("#searchNote").fileTree({data: scope.filedata,sortable: false,selectable: false});</script>'
    }
});

Someone know why I cant execute Javascript in a Directive or know how to do it?

0

2 Answers 2

2

You dont need to use the id, use 'element' directly.

app.directive("showFileBrowser", function() {
    return {
        restrict: 'E',
        link: function($scope, element, attrs) {    
          $(element).fileTree({data: scope.filedata,sortable: false,selectable: false});
        }
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the advice with the element parameter. But still it dont work.
you console may have fired errors, like a problem with filedata because i failed, it's $scope.filedata and not scope.filedata. try to put console.log to help you
No my console dont show anything. It look like everything works fine. My answer show you one method that works.
0

It works fine if I return a function, but i prefer return an Object.

 app.directive("showFileBrowser", function() {
    return function(scope, element, attr) {
        $(element).fileTree({data: scope.filedata,sortable: false,selectable: false});
   }       
});

Comments

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.