首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态添加uib折叠页眉标签

动态添加uib折叠页眉标签
EN

Stack Overflow用户
提问于 2016-04-27 15:31:12
回答 1查看 460关注 0票数 1

在下面的文档中,我希望通过mtaa- HTMl -facts指令动态添加uib header属性。有可能吗?我试图创建该指令,但它给出了一个错误libs.min.js:117 TypeError: n is not a function

我想在<div class="mtaa-document-title">下面和后面插入标记<uib-accordion-heading>,以帮助它控制手风琴。

HTML

代码语言:javascript
复制
<uib-accordion close-others="oneAtATime">   
                    <uib-accordion-group is-open="status.open" class="mtaa-documents-facts" mtaa-document-facts>

                            <!--document list component-->
                            <div class="mtaa-document-list-component">
                                    <!-- <uib-accordion-heading> -->

                                            <div class="mtaa-document-title">
                                                <h5 class="mtaa-document-title-text">Documents and Forms</h5>
                                                <span class="mtaa-arrow-expand visible-xs visible-sm hidden-md hidden-lg"><i class="glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
                                                </span>
                                            </div>

                                    <!-- </uib-accordion-heading>        -->

                                            <div class="mtaa-document-link">
                                                <span class="icon-forms mtaa-document-link-icon"></span>
                                                <a href="#"> Direct Debit form <span class="icon-longarrowright"></span></a>
                                            </div>
                                            <div class="mtaa-document-link">
                                                <span class="icon-forms mtaa-document-link-icon"></span>
                                                <a href="#"> Direct Debit form <span class="icon-longarrowright"></span></a>
                                            </div>
                                            <div class="mtaa-document-link">
                                                <span class="icon-forms mtaa-document-link-icon"></span>
                                                <a href="#"> Direct Debit form <span class="icon-longarrowright"></span></a>
                                            </div>
                            </div>

                        <!--quick fact component--> 
                            <div class="mtaa-quick-fact-container">
                                <div class="mtaa-margin-top-small"></div>
                                <div class="mtaa-quick-fact-component mtaa-background-quick-fact" style="height:auto"> <!--From this part will go into sitecore-->
                                    <div class="mtaa-quick-fact mtaa-quick-fact-primary">
                                        <a href="#">
                                            <div class="mtaa-quick-fact-title">
                                                <h2>80%</h2>
                                            </div>
                                            <div class="mtaa-quick-fact-description">
                                                This is link text with arrow icon <span class="mtaa-quick-fact-description-icon icon-longarrowright"></span>
                                            </div>
                                        </a><!-- This is link text with arrow icon -->
                                    </div>
                                </div><!-- Ends-->
                            </div>

                    </uib-accordion-group>
                </uib-accordion>    

方向

代码语言:javascript
复制
(function() {
    angular
        .module("mtaa.main")
        .directive("mtaaDocumentFacts",[ headerFactory ]);

    function headerFactory($compile) {
        let directive = {

            restrict: "A",
            compile: compile,
            link: link
        };

        function link(scope,ele) {

        }

        function compile(scope,tElem, tAttrs){

                console.log(': compile');

                return {
                  pre: function(scope, iElem, iAttrs){

                  },
                  post: function(scope, iElem, iAttrs){
                      console.log('link:' + iElem[0].getElementsByClassName('mtaa-document-title')); 
                      var html  = iElem[0].getElementsByClassName('mtaa-document-title').innerHTML;
                      var finalHtml = '<uib-accordion-heading>' + html + '</uib-accordion-heading>';
                      $compile(finalHtml)(scope);  
                  }
              }
        }

        return directive;
    }
})();
EN

回答 1

Stack Overflow用户

发布于 2016-04-27 19:36:26

我得到了解决方案,错误是因为我没有在指令中包含编译服务。但这里的解决方案只需在compile函数中添加新的DOM节点,我认为这是默认的compile pre事件。

以下是指令

代码语言:javascript
复制
/*
  directive to append 
  dynamic uib header for accordion
*/

(function() {
    angular
        .module("mtaa.main")
        .directive("mtaaDocumentFacts",[ documentFactsFactory ]);

    function documentFactsFactory() {
        let directive = {

            restrict: "A",
            compile: compile
        };


        function compile(scope,tElem, tAttrs){

                let arrowIcon = '<span class="mtaa-arrow-expand visible-xs visible-sm hidden-md hidden-lg"><i class="glyphicon" ng-class="{"glyphicon-chevron-down": '+status.open+', "glyphicon-chevron-right": '+!status.open+'}"></i>';
                // <span class="mtaa-arrow-expand visible-xs visible-sm hidden-md hidden-lg"><i class="glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
                //         </span>
                //need better navigation approach through jQlite
                let titleHtml  = angular.element(tElem['$$element'][0].children[0].children[0]).html() + arrowIcon;
                let finalHtml = '<uib-accordion-heading><div class="mtaa-document-title">'+ titleHtml + '</div></uib-accordion-heading>';
                angular.element(tElem['$$element'][0].children[0].children[0]).empty().html(finalHtml)


                //using jQuery
                  // let titleHtml  = $(tElem['$$element']).find('.mtaa-document-title').html() + arrowIcon;
                  // let finalHtml = '<uib-accordion-heading><div class="mtaa-document-title">' + titleHtml + '</div></uib-accordion-heading>';
                  // $(tElem['$$element']).find('.mtaa-document-title').html(finalHtml);     


                return {
                  pre: function(scope, iElem, iAttrs){
                  }
              }
        }

        return directive;
    }
})();

仍在努力让ng-class属性工作,如果可以,请提供任何帮助。

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

https://stackoverflow.com/questions/36883201

复制
相关文章

相似问题

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