0
我试图在指令中输出子元素ID,但它保持打印非插值的值。我不知道如何实现....请帮助。指令:链接功能的孩子不插值
我努力学习的角度...
//////////////////////
//Directive example
app.directive('simpleNumber', ['$http', '$compile', function($http, $compile) {
return {
restrict: 'A', /*Example: <span simple-number></span>*/
terminal: true,
transclude: true,
replace: true, /*Replace <simple-number-ctrl> tag with below template*/
template: "<div><div id=\"{{$id}}\"></div></div> ",
scope: { /*data-binding to parent scope*/
ctrlWidth: "@", /*one way binding*/
strNumber: "=", /*two way binding*/
onWidthChanged: "&" /*Event function fired*/
},
link: function($scope, elm, attrs) {
console.log(elm.children()[0].id); //This is printing {{$id}} !!! I AM CONFUSED
}
};
}]);
<span simple-number ctrl-width="100px" str-number="numberText" on-width-changed="onWidthChanged(width);"><font color=green>Transcluded text</font></span>
以下是控制台输出 **之前绑定进行评估** 绑定还未评估:
摘要叫** **后(按照您的例子) $消化后,绑定被评估 –奇怪,我记得在发送解决方案之前测试它。你可以尝试没有unwatch()调用吗? – Yann