最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular.js -- use ng-show to show element only if other element is not disabled - Stack Overflow

programmeradmin1浏览0评论

I have an element that I would like to show only when another form element is NOT disabled.

<input ng-model="myModel">

None of the following work:

<div ng-show="myModel">

This will show if the input is disabled, as long as it has had a value set in the past.

<div ng-show="myModel.enabled">
<div ng-show="!myModel.disabled">

Those props don't seem to exist.

<div ng-show='!angular.element(po.vendor__contact).prop("disabled")'>

Thought that might work to ask jQuery if it's disabled, but it doesn't.

Is there any way to reference whether an element is enabled or not in an Angular directive? Can it be done by asking jQuery?

Thanks!

Fiddle: /

I have an element that I would like to show only when another form element is NOT disabled.

<input ng-model="myModel">

None of the following work:

<div ng-show="myModel">

This will show if the input is disabled, as long as it has had a value set in the past.

<div ng-show="myModel.enabled">
<div ng-show="!myModel.disabled">

Those props don't seem to exist.

<div ng-show='!angular.element(po.vendor__contact).prop("disabled")'>

Thought that might work to ask jQuery if it's disabled, but it doesn't.

Is there any way to reference whether an element is enabled or not in an Angular directive? Can it be done by asking jQuery?

Thanks!

Fiddle: http://jsfiddle/ADukg/3197/

Share Improve this question edited Jun 20, 2013 at 9:57 mrjf asked Jun 20, 2013 at 9:48 mrjfmrjf 1,1371 gold badge12 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I think your not using Angular the right way. You should not base the visibility of an element based on the state of another element.

Both elements should depend on the model:

<input ng-model="myModel" ng-disabled="isDisabled">
<div ng-hide="isDisabled">

Basically, view reflects the model, don't inspect the DOM, and don't use jQuery. Also you can use ng-hide instead of ng-show and !

Edit: http://jsfiddle/ADukg/3198/

发布评论

评论列表(0)

  1. 暂无评论