我目前正在开发Validation指令。一切正常但链接函数被调用,即使输入元素位于一个元素内部,该元素将通过" ng-if"隐藏。
有没有办法检查元素是否在隐藏的ng-if元素中?
我的指示:
/Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:245
throw(ex);
^
Error: Must throw non-empty error
at Object.Future.throw (/Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:259:10)
at /Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:541:23
at runWithEnvironment (/Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:139:21)
at /Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/fiber-helpers.js:146:14
at /Users/user1/.meteor/packages/meteor-tool/.1.1.4.xh5uo++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/tools/buildmessage.js:549:11
标记
validationModule.directive("validateText", ['ValidationService', '$filter', function (ValidationService, $filter) {
return {
link: function (scope, element, attrs) {
//validation magic
}
};
}]);
答案 0 :(得分:0)
试试这个:
element.offsetParent === null
where元素是您要测试可见性的DOM元素
答案 1 :(得分:0)
你可以试试这个 -
validationModule.directive("validateText", ['ValidationService', '$filter', function (ValidationService, $filter) {
return {
link: function (scope, element, attrs) {
//validation magic
if(scope.initDataSource.IsReadOnly)
{
}
}
};
}]);
答案 2 :(得分:0)
我找到了满足我需求的解决方案。我正在收听$ destroy事件并在发生时撤消我的验证
scope.$on("$destroy", function () {
ValidationService.Unvalidate(element, attrs.ngModel);
});