首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何动态使用ng-animate

如何动态使用ng-animate
EN

Stack Overflow用户
提问于 2014-04-07 22:50:05
回答 1查看 311关注 0票数 0

我有两个简单的容器,第一个包含一个指令,当我点击它时,指令将触发函数,在该函数中,我想动态添加和删除其他contianer上的ng-animate,这些常量应该在条件下变为活动和非活动

代码语言:javascript
复制
<div class="form-group">
         <div>
            <yesno-button class="radioField" show-hide ng-click="showChildFields(ev)"></yesno-button>
            <label class="radio-inline control-label">1st Container</label>
        </div>
</div>
<div class="form-group" style="display:none;">
        <div>
            <yesno-button class="radioField"></yesno-button>
            <label class="radio-inline control-label">2nd Container</label>
        </div>
</div>   

我有一个show-hide指令定义

代码语言:javascript
复制
module.directive("showHide", function () {

    return {


        link: function (scope, element, attrs, controller) {

            scope.showChildFields = function (ev) {
                    //need to enable and disbale 2nd container with ng-animation
            };
        }
    };
});
EN

回答 1

Stack Overflow用户

发布于 2014-04-08 01:00:28

使用ng-show可以达到预期的效果。在单击第一个yesno-button时设置一个布尔变量。然后,当该变量为真时,使用ng-show显示第二个容器。

代码语言:javascript
复制
<div class="form-group">
  <div>
    <input type="button" ng-click="container.showChildren = !container.showChildren" value="Yes/No"/>
    <label class="radio-inline control-label">
      1st Container
    </label>
  </div>
</div>
<div class="form-group animate-show" ng-show="container.showChildren">
  <div>
    <input type="button" value="Yes/No"/>
    <label class="radio-inline control-label">
      2nd Container
    </label>
  </div>
</div> 

请注意,第二个容器具有类animate-show,因此将应用动画。

下面是一个演示,改编自ng-show应用编程接口文档:http://plnkr.co/WdQ4Y1ARxsWkUhEf7pA1

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22915849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档