Используйте функцию для templateURL в AngularJS с Typescript - PullRequest
0 голосов
/ 06 октября 2018

У меня есть следующее:

export class MyComponent implements ng.IComponentOptions {
    public static componentName: string = "myViewer";

    public bindings: any;
    public controller: any;
    public controllerAs: any;
    public templateUrl: string;

    constructor() {
        this.bindings = {
            configName: '@'
        };

        this.controllerAs = "ctrl";
        this.controller = MyController;
        this.templateUrl = 'scripts/components/my-viewer/my-viewer.html';
    }

}

Я хочу иметь возможность динамически указывать templateURL, включая его в привязки:

this.bindings = {
                configName: '@',
                templateURL: '=?'
            };

И затем использовать функцию дляtemplateURL (см. https://ng -table.com / api-docs / interfaces / angular.icomponentoptions.html )

В предварительно набранной версии кода я мог бы сделать что-то вроде:

templateUrl: function ($element, $attrs) {
      return '<SomeLogicToChooseTheTemplate>';
    }

Как я могу заставить что-то подобное работать в версии Typescript?

1 Ответ

0 голосов
/ 07 октября 2018

Использование:

this.templateURL = function(elem: IAugmentedjQuery, attrs: Iattributes) : string {
    return '<SomeLogicToChooseTheTemplate>';
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...