[英]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.