0

I'm using angularJS 1.6 directive to add some jQuery libs. Now i'm using it so:

let SomeDirective = function ($timeout) {
  'ngInject';

  return {
    restrict: 'A',
    link: function (scope, element, attrs) {

      $timeout(function () {
        element.somePlugin(JSON.parse(attrs.params));
      });

    }
  };
};

export default SomeDirective;

due to that fact, that I set some-directive on html object, which is loaded from the server, i think angular didn't understand, when apply this directive...

But i think this approach is strange and ugly... How can i fix this directive?

By the way, adding in scope isLoaded variable (and watch it in directive) didn't resolve my problem

1 Answer 1

2

You can use $scope.$evalAsync(). Refer https://docs.angularjs.org/api/ng/type/$rootScope.Scope.

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

5 Comments

can you provide additional data? in my case it's not working in every case
can you explain what you exactly want??
plugin isn't executed... if i change timeout(function () { to scope.$evalAsync(function () {
What's the problem with $timeout??
yes, it is that's why it is there. It is suitable for your situation because you need to wait for some time so that plugin gets initialized.

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.