如何根据角度js指令获得绑定的值restrict: 'A'?
<span directiverestrict> {{binding}} </span>
Run Code Online (Sandbox Code Playgroud)
我尝试使用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}}'
}
};
});
Run Code Online (Sandbox Code Playgroud)
您可以使用该$interpolate服务,例如
.directive('logContent', function($log, $interpolate) {
return {
restrict: 'A',
link: function postLink(scope, element) {
$log.debug($interpolate(element.text())(scope));
}
};
});
Run Code Online (Sandbox Code Playgroud)
<span directiverestrict bind-value="binding"> {{binding}} </span>
Run Code Online (Sandbox Code Playgroud)
脚本
directive("directiverestrict", function () {
return {
restrict : "A",
scope : {
value : '=bindValue'
},
link : function (scope,ele,attr) {
alert(scope.value);
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5549 次 |
| 最近记录: |