如何基于AngularJS指令restrict: 'A'
获取绑定的值?
<span directiverestrict> {{binding}} </span>
我尝试使用 elem[0].innerText
,但它返回的是准确的绑定 '{{binding}}'
而不是绑定的值。
.directive('directiverestrict',function() {
return {
restrict:'A',
link: function(scope, elem, attr) {
// I want to get the value of the binding enclosed in the elements directive without ngModels
console.log(elem[0].textContent) //----> returns '{{binding}}'
}
};
});