且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJS指令中的可选表达式属性

更新时间:2023-02-21 20:14:13

你可以通过chaning $ $来赚取你的工作eval调用

You could make what you have work by chaning your $eval call to

scope.$parent.$eval(attrs.disable);

因为您需要评估 attrs.disable $中包含的表达式c $ c>在父范围内,而不是指令的隔离范围。但是,由于您使用的是'&'语法,因此它将自动评估父作用域中的表达式。所以只需执行以下操作:

because you need to evaluate the expression contained in attrs.disable in the parent scope, not the directive's isolate scope. However, since you are using the '&' syntax, it will evaluate the expression in the parent scope automatically. So just do the following instead:

if(angular.isDefined(attrs.disable)) {
    scope.disable();
}

小提琴。