如何手动获得$ ATTR在角 [英] how to obtain $attr manually in angular

查看:161
本文介绍了如何手动获得$ ATTR在角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么可以手动获取从linkFn回调的属性。

I want to know how I might manually obtain the attribute from the linkFn call back.

例如。如果我想的范围,我这样做,

e.g. if I want scope, I do,

angular.element(element).scope()

控制器

angular.element(element).controller('ngModel')

怎么样在ATTR。

how about for attr.

推荐答案

在父控制器我想你可以访问属性后首次将其分配给该指令的作用域属性对象

In the parent controller I suppose you could access the attributes object after first assigning it to a scope property in the directive:

<div ng-controller="MyCtrl">
    <div my-directive attr1="one">see console log</div>
</div>

app.directive('myDirective', function() {
    return {
        link: function(scope, element, attrs) {
            scope.attrs = attrs
        },
    }
});

function MyCtrl($scope, $timeout) {
    $timeout(function() {
        console.log($scope.attrs);
    }, 1000);
}

<大骨节病> 小提琴

这篇关于如何手动获得$ ATTR在角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆