0
我有一個指令,我需要在通過屬性傳遞的位置訪問作用域。從指令中的作用域路徑訪問模型
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/
非常感謝,第二個完全正確,我需要。 – Delremm