0

I am trying to change the attribute that is passed in to the third party directive md-icon. I tried by delegating, but the value does not change.

So far this is what I have.

angular.module('app').decorator('mdIconDirective', function ($delegate) {
let directive = $delegate[0];
let compile = directive.compile;

directive.compile = function(el, attrs) {
    let link = compile.apply(this, arguments);

    return function(scope, el, attrs) {
        let src = `node_modules/@mdi/svg/svg/${attrs.mdSvgSrc}.svg`;
        el[0].setAttribute('mdSvgSrc', src);

        link.apply(this, arguments)
    };
};

return $delegate;
});

I want to change the value passed in md-svg-src so that I don't have to write the full path every time.

1 Answer 1

0

I want to change the value passed in md-svg-src so that I don't have to write the full path every time.

You may not want to make separate HTTP requests for every icon, so you can bundle your SVG icons together and pre-load them with $mdIconProvider as an icon set. An icon set can also be given a name, which acts as a namespace for individual icons, so you can reference them like "social:cake".

app.config(function($mdIconProvider) {
    $mdIconProvider
      .iconSet('social', 'img/icons/sets/social-icons.svg', 24)
      .defaultIconSet('node_modules/@mdi/svg/svg/core-icons.svg', 24);
});

This technique can be used to avoid using the full path each time.

<md-icon md-svg-icon="social:android" aria-label="android "></md-icon>

For more information, see

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

1 Comment

I appreciate your reply, but I really need to know how to manupulate an attribute binding before it's sent to the 3rd party directive. Thanks

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.