0

Hello everybody and happy new year !

I try to insert the parameter $ctrl.configFile.samples into src but I do something wrong and get an error on the console (like iframe src read $ctrl.configFile.samples or something like that):

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
                    })
                }

2 Answers 2

1

JS treats $ctrl.configFile.samples as pure string, if you want to get content of that variable you have to write it in this form:

src="${ $ctrl.configFile.samples }"

With template literals you can access variables like this: `some string... ${variable} ... rest of the string.

Read more about template literals.

Sign up to request clarification or add additional context in comments.

2 Comments

now it throwing console err :$ctrl is not defined. edited : works ! using this. instead $ctrl.
@TomCohen You should vote for answer, if you think it's helpful. Thanks!
1

use single quotation like this,

'<md-toolbar class="root-container">
<iframe width="1280" height="720" src=" ' + $ctrl.configFile.samples + '" frameborder="0" scrolling="yes"></iframe> '

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.