[英]AngularJS Passing parameter to directive's template
我有这个基本设置
的HTML
<linear-chart chartData="myArray" height="666"> </linear-chart>
JS ...
... app.directive('linearChart', function($window){ return{ restrict:'EA', template:"<svg width='850' height={{myHeight}} ></svg>", ******-> if I hard code height with number all great but when trying to pass as arg it goes kapput with/without the quotes link: function(scope, elem, attrs){ var salesDataToPlot=scope[attrs.chartData]; scope.myHeight = attrs.height; console.log('h passed=', scope.myHeight); *****-> prints out the proper value 666 ...
尝试将高度作为参数传递时,出现以下错误:属性高度:预期长度“ {{myHeight}}”。
如此纯真的东西,但我找不到类似的情况/答案,或者我是否以错误的方式将其值传递给模板???
更新
感谢bhantol和Kristiyan,尽管Chrome中的属性仍在指令中设置,但角度代码仍未转换范围。myHeight,我通过Chrome调试器,经过几次试验后,我找到了解决方法,它就在这里
... template: function(scope,elem) { var myTemp = '<svg width="850" height="' + elem.height + '"></svg>'; return myTemp; }, ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.