首页 > 解决方案 > 角度中的两种方式绑定将变量作为字符串而不分配变量属性

问题描述

html:

<div tile-component included-svg='::installController.installUpdatesSvg'></div>

安装控制器:

 **there is a scope variable 'installUpdatesSvg'**
this.installUpdateSvg = 'xyzSvg';

指示:

.directive('tileComponent',
   ['cvLoc','$timeout','$sce',
     function(cvLoc, $timeout,$sce) {
        return {
            restrict : 'EA',
            transclude : true,
            scope : {
                includedSvg : '=?'

            },
            link : function(scope, ele, attrs) {
                scope.includedSvgHtmlContent = $sce.trustAsHtml(attrs.includedSvg).$$unwrapTrustedValue(); 
            }
]);

在 attrs.includedSvg 中,我得到 '::installController.installUpdatesSvg' 而不是 'xyzSvg';

标签: javascriptangularjs

解决方案


你有没有试过这样: <div tile-component included-svg='{{ installUpdatesSvg }}'></div>

而是使用this.installUpdatesSvg, 使用scope.installUpdatesSvg


推荐阅读