0

Good morning everybody,

After lots of search about this subject, I could find how to get things bound, but I could not find a way to get the value from the component templateUrl.

Anyone knows how to get this value templateUrl from a component inside of $onInit of the associated controller?

Thank you all for your time!


That is my issue, my scope object i am getting empty for the templateUrl:

Component

let newComponent = {
    templateUrl: 'components/new-component/template/field.html',
    controller: TemplateController,
    controllerAs: 'tr',
    bindings: {
        templateUrl: '<'
    }
}

Controller

"use strict";


TemplateController.$inject = ['$scope','$element'];

// Controller Constructor
function TemplateController($scope, $element) {

    // Creating the view model reference
    let vm = this;

    vm.$onInit = function () {
        try {

            console.log($scope.templateUrl);
            debugger;

        } catch (e) {
            console.log(e);
        }
    }

}

export default TemplateController;
2
  • What is your use case for needing to access it? Commented Mar 8, 2021 at 12:44
  • I want to get the reference for each component and use the template url to print different cases. Commented Mar 8, 2021 at 15:00

1 Answer 1

0

You need to pass template-url attribute for that new component in html file and in that attribute you need to pass that location of that file and in binding you already have templateUrl variable so you can add this in your code to make it working

In html file

<new-component template-url = "components/new-component/template/field.html"></new-component

If you use like this for each component with specific location. It will print location of each file for each component. I think you can print this value in that component controller.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.