javascript - 角度中的两种方式绑定将变量作为字符串而不分配变量属性
问题描述
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';
解决方案
你有没有试过这样:
<div tile-component included-svg='{{ installUpdatesSvg }}'></div>
而是使用this.installUpdatesSvg
, 使用scope.installUpdatesSvg
推荐阅读
- c# - Fluent Validation:如何将整数列表作为属性进行单元测试
- amazon-web-services - AWS Cloudformation:密钥对“chaklader.pem”不存在(服务:AmazonEC2;状态代码:400;错误代码:InvalidKeyPair
- python - python - 等待 Iterable 中的所有协程
- go - Golang-参数太多
- javascript - 无法使用 Puppeteer 单击按钮
- javascript - React 路由到新组件,尝试 setState,然后得到“无法对未安装的组件执行 React 状态更新”。
- angular - 打字稿 .subscribe
- javascript - 编辑表后如何从 mutator 模块中的任何行获取值?
- sql - 查询 Azure Cosmos DB 多个文档的高效方法
- sql - SQL - 返回第 n 个出现的行