打字稿:具有指令的默认值

时间:2017-04-17 18:54:59

标签: typescript data-binding angularjs-directive

在我的指令中,我有变量index如下:

   export class MyDirective implements ng.IDirective {
    public static factory(): ng.IDirectiveFactory {
        return () => new MyDirective ();
    }

    public restrict = "E";
    public templateUrl = "test.html";
    public controller = DirectiveController;
    public controllerAs = "vm"; 
    public scope = {};
    public bindToController = {
        index: "<?"
    };

在指令的控制器中我设置索引的默认值,如下所示:

 export class DirectiveController {
    private index: number = 0;...

问题是当父html设置index的值时,它仍显示为0

<my-directive index="3"></my-directive> //not working still index is 0

如何设置默认值,如果给定的值使用给定值而不是默认值?

0 个答案:

没有答案