如何显示angular.js点击股利previous格 [英] how to show previous div of clicked div in angular.js

查看:103
本文介绍了如何显示angular.js点击股利previous格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个HTML

i have a html like this

  <div  class="main" ng-controller="firstcontroller">
       <div class="submain">
           <div class="first" ng-show="display">displayed</div>
           <div class="second" my-directive>click</div>
       </div>
       <div class="submain">
           <div class="first" ng-show="display">displayed</div>
           <div class="second" my-directive>click</div>
       </div>
       <div class="submain">
           <div class="first" ng-show="display">displayed</div>
           <div class="second" my-directive>click</div>
       </div>
 </div>

我控制器这样的

     app.controller('firstcontroller',function($scope)
     {
         $scope.display=false;

     });

我的指令编码像这样

my directive coding like this

 app.directive('myDirective',function(scope, element, attrs)
 {
    return function()
    {
        element.bind('click',function()
       {
             element.prev().show();
            //alert(element.prev().attr('class'));

        //   element.parent().find('.main').append('<div>Some text</div>')
       });


    }

 });

在这里最初的div也会在div有类名称的拳头,只有DIV上课名第二,将显示隐藏。所以当我们点击点击DIV,我们必须表明的,只有previous格点击DIV .....如何显示angular.js点击股利previous格?

here initially div will be hidden if div has class name fist , only div having class name second will be displayed . so when we click on click div we have to show only previous div of that clicked div..... how to show previous div of clicked div in angular.js ?

推荐答案

我得到的问题是缺少信息的感觉。例如。是 .submain div的硬$ C $的CD,或者通过迭代产生的?

I get the feeling that the question is missing information. E.g. are the .submain divs hardcoded, or created by iteration?

如果然而,这确实是如此,该指令是多余的。更改HTML如下:

If however this is indeed the case, the directive is redundant. Change the HTML as:

<div  class="main" ng-controller="firstcontroller">
   <div class="submain">
       <div class="first" ng-show="display[0]">displayed</div>
       <div class="second" ng-click="display[0] = !display[0]">click</div>
   </div>
   <div class="submain">
       <div class="first" ng-show="display[1]">displayed</div>
       <div class="second" ng-click="display[1] = !display[1]">click</div>
   </div>
   <div class="submain">
       <div class="first" ng-show="display[2]">displayed</div>
       <div class="second" ng-click="display[2] = !display[2]">click</div>
   </div>
</div>

和控制器:

 app.controller('firstcontroller',function($scope) {
     $scope.display=[false, false, false];
 });

这篇关于如何显示angular.js点击股利previous格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆