我有一个指令,我需要在通过属性传递的位置访问范围。
HTML:
<div my-directive scope-location="settings.main.url">
...
</div>
指示:
link: function(scope, elm, attrs) {
// How can I do
// scope['settings']['main']['url'] = angular.element(elm).text();
// where "['settings']['main']['url']" comes part from attr "scope-location"
// with value "settings.main.url"?
scope[attrs.scopeLocation] = angular.element(elm).text();
}
小提琴:http: //jsfiddle.net/GEhSG/3/