AngularJs directive-controller实例

前端之家收集整理的这篇文章主要介绍了AngularJs directive-controller实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.代码

<body ng-app="myApp">
    <my-site value="http://www.tianma3798.cn/" text="爱短句">爱短句1</my-site>
    <div my-site class="bg-danger" value="http://www.tianma3798.cn/" text="爱短句">爱短句2</div>
</body>
var app = angular.module('myApp',[]);
app.directive('mySite',function () {
    return {
        restrict: 'EA',transclude: true,controller: function ($scope,$element,$attrs,$transclude) {
            $transclude(function (clone) {
                var a = angular.element('<a>');
                a.attr('href',$attrs.value);
                a.text(clone.text());
                $element.append(a);
            });
        }
    }
});

猜你在找的Angularjs相关文章