javascript - 在使用ng-repeat制作组件的时候,在添加ng-click事件之后,怎么设置点击展示一个,隐藏其他的
怪我咯
怪我咯 2017-04-11 11:42:09
[JavaScript讨论组]
(function () {
    'use strict';

    angular.module('ui.component.commentContent',[])
        .directive('uiComponentCommentContent',commentContent)
    commentContent.$inject = [];
    function commentContent(){
    return {
        restrict: 'EA',
        // template:
        // '

'+ // '

'+ // '

{{commentContent.term}}

'+ // '

' + // '

'+ // '

'+'

'+ // '

', // replace: true, transclude: true, scope:{ commentContent:"=", isShow:"@", }, templateUrl:"components/uiComponents/commentContent/commentContent.tpl.html", controller: function ($scope) { $scope.show = function () { // $scope.isShow = !$scope.isShow; if($scope.isShow == 'true'){ $scope.isShow = 'false'; }else{ $scope.isShow = 'true'; } } }, }; }; }());

{{commentContent.term}}

如上,我写了个组件,然后我调用的时候使用ng-repeat调用 现在做到了点击能单个的展示或者隐藏,怎么做到点击展示其中一个但是隐藏其他的呀?
怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(2)
迷茫

点击时传个$index进去,判断展开隐藏时多判断一下当前index跟传进去了index相不相等

怪我咯

我没非常仔细得看,暂时说几点:
1,我猜测你在你的controller里写了$scope.show的方法, 而没有贴出来, directive中的controller并不是你想的那种用法, 所以directive中的controller用你的那种方法是不会调用的。
2,写法方面 $scope.isshow = !$scope.isshow就可以了, 你觉得呢。
3,完成你的需求需要嵌套指令, 你可以参考一下angular-bootstrap的手风琴写法
4,如果我空下来回来还没有人解答你我可以稍微给你写个大概思路

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号