How to set a native attribute from AngularJS directive?

前端 未结 3 1316
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 03:39

I\'d like to write HTML similar to:

test

And ha

3条回答
  •  旧时难觅i
    2020-12-30 04:19

    test
    
    

    app.directive('fullPath', function() {
        return {
            link: function(scope, element, attrs) {
                var fullPathUrl = "http://.../";
                if(element[0].tagName === "A") {
                    attrs.$set('href',fullPathUrl + attrs.fullPath);
                } else {
                    attrs.$set('src',fullPathUrl + attrs.fullPath);
                }
            },
        }
    });
    

    I don't know where you are getting fullPathUrl from, so I hardcoded it in the link function.

提交回复
热议问题