【发布时间】:2016-01-08 08:35:54
【问题描述】:
我的问题基本上是让编译器获得我在指令中添加的新属性。 我正在使用打字稿,我有这样的东西。
public class MyDirectiveScope: ng.IScope
{
foo: boolean;
}
public class MyDirective implements ng.IDirective
{
public restrict = 'A';
public scope = {
foo:'=',
};
public constructor (protected $log: ng.ILogService)
{
}
link = ($scope: MyDirectiveScope, element: JQuery, attributes: ng.IAttributes)
{
if(!$scope.foo)
angular.element(element).attr("ng-if","false");
}
}
我调用指令的元素获取了我添加的新属性,但 angular 没有评估这个新属性。例如,如果我有一个 <div> 元素获取这个新属性并且类似于 <div ng-if="false">, 我希望不会显示 div 内的内容。
我在 angular.element(element).css("display", "none") 之前使用过,这很有效,但我真的希望 div 元素根本不在 DOM 中。
【问题讨论】:
-
尝试在指令构建的编译阶段而不是链接。
标签: angularjs html angularjs-directive typescript