在我的指令中,我有变量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
如何设置默认值,如果给定的值使用给定值而不是默认值?