大家好,新年快乐!
我尝试将参数 $ctrl.configFile.samples
插入 src,但我做错了一些事情并在控制台上收到错误(例如 iframe src read $ctrl.configFile.samples
或类似的东西):
Failed to load resource: net::ERR_FILE_NOT_FOUND
function _downloadSamples() {
var filePath = path.join(__dirname,'/../','/../config.json');
this.configFile = JSON.parse(fs.readFileSync(filePath, 'utf8'));
$mdDialog.show({
controller: sideActionsController,
controllerAs: '$ctrl',
template:
`
<md-toolbar class="root-container">
<iframe width="1280" height="720" src="$ctrl.configFile.samples" frameborder="0" scrolling="yes"></iframe>
`,
bindToController: true,
clickOutsideToClose: true,
fullscreen: true,
parent: $rootScope.parentEl
})
}
最佳答案
JS 将 $ctrl.configFile.samples 视为纯字符串,如果你想获取该变量的内容,你必须以这种形式编写它:
src="${ $ctrl.configFile.samples }"
使用模板文字,您可以访问如下变量:“某些字符串... ${variable} ... 字符串的其余部分。
了解更多关于template literals的信息.
关于javascript - 如何将变量插入到html src中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48041421/