简体   繁体   English

这个标签有什么作用?

[英]What does this tag do?

I have been learning how to read other people's code and when ever I see something like this <meganav-item item="item" ng-repeat="item in website.nav.primary"></meganav-item> I get stuck. 我一直在学习如何阅读他人的代码,并且每当<meganav-item item="item" ng-repeat="item in website.nav.primary"></meganav-item>看到类似这样的<meganav-item item="item" ng-repeat="item in website.nav.primary"></meganav-item>我都会被卡住。

I have a basic understand of angular, but the problem is the <meganav> tag. 我对角度有基本的了解,但是问题是<meganav>标记。 I do not know what this is..I have done a Google search, but nothing useful is showing. 我不知道这是什么。我已经完成了Google搜索,但没有显示任何有用的信息。

Update 更新资料

I have managed to locate the file of the <meganav> element. 我设法找到<meganav>元素的文件。 After following the instructions from the links that you guys have provided, it led me to a file named "MegaNavItem.js". 按照你们提供的链接中的说明进行操作后,它将我带到一个名为“ MegaNavItem.js”的文件。 Here is the code: 这是代码:

window.tcoStore.directive('meganavItem', ['$timeout','transport', function($timeout,transport) {
    var lockTimeout = false;
    var meganavLocks = transport.getModel('meganavLocks', {lock : false});
    var clear = function (){
        if(meganavLocks.timeout){
            $timeout.cancel(meganavLocks.timeout);
        }
    }
    var action = function(callback, time) {
        if(meganavLocks.lock){
            return;
        }
        clear();
        meganavLocks.timeout = $timeout(callback, time);
    }
    var dropLock = function(callback, time) {
        meganavLocks.lock = false;
    }
    return {
        restrict : 'E',
        replace: true,
        templateUrl : '/page/header/meganav/item.html',
        scope : {
            item : '=',
            clickOnly : '@',
            delayIn : '@',
            delayOut : '@'
        },
        link : function($scope, elem, attrs){
            if(!$scope.clickOnly){
                $scope.delayInValue = parseInt($scope.delayIn || 300,10);
                $scope.delayOutValue = parseInt($scope.delayOut || 500,10);

                elem.on('mouseenter', $scope.showDelayed);
                if($scope.delayOutValue > 0){
                    elem.on('mouseleave', $scope.hideDelayed);
                }
            }
        },
        controller: ['$scope', '$timeout', 'transport', '$location' ,
            function($scope, $timeout, transport,$location) {

            // When $location changes ...
            $scope.$on('$locationChangeSuccess', function() {
                $scope.hide(true);

                $scope.isActive = !_.isUndefined($scope.item.link) && ($scope.item.link.replace(/\/+$/,'') == $location.path().replace(/\/+$/,''));
            });

            $scope.loadSubmenu =0;

            //  tranposrt model accessable by other items
            var meganavVisibleModel = transport.getModel('meganavActive');
            var meganavVisibleModelId = $scope.item.$$hashKey;
            meganavVisibleModel[meganavVisibleModelId] = false;

            // hide and show funs
            $scope.hide  = function(forceFullClose){
                clear();
                meganavVisibleModel[meganavVisibleModelId] = false;
                if(forceFullClose) {
                    meganavLocks.lock = true;
                    $timeout.cancel(lockTimeout);
                    lockTimeout = $timeout(dropLock, 1000);
                }
            };


            $scope.hideDelayed = function (delay) {
                action($scope.hide, _.isNumber(delay) ? delay : $scope.delayOutValue);
            };

            $scope.show  = function(){
                if(meganavLocks.lock){
                    return;
                }
                clear();
                $scope.loadSubmenu = 1;
                for(var i in meganavVisibleModel){
                    meganavVisibleModel[i] = (meganavVisibleModelId == i);
                }
            };

            $scope.showDelayed = function (delay) {
                action($scope.show, _.isNumber(delay) ? delay : $scope.delayInValue);
            };

            $scope.$watch(function(){
                $scope.visible = meganavVisibleModel[meganavVisibleModelId];
            });


            // first touch click, second touch go to link
            $scope.touch = function($event, path){
                if(!$scope.visible) {
                    //$event.preventDefault();
                    $scope.show();
                }else if(tco.empty(path)) {
                    $scope.hide();
                } else {
                    if(path.match(/^https?:/)){
                        window.location.href = path;
                    }else{
                        $location.path(path);
                    }
                }
            }

        }]
    }
}]);

And this file led me to another file named item.html. 这个文件将我带到另一个名为item.html的文件。 The code : 编码 :

<li class="header--menu__item my-repeat-animation" ng-class="{ 'is-active': isActive, open : visible && item.groups.length}" off-click="hide()" >
    <a ng-if=":: item.groups.length"
        ng-class="{active: item.active}"
        class="header--menu__item--link has-children"
        ng-click="show()"
        title="{{::item.name}}">
        {{::item.name}}
    </a>
    <a ng-if=":: !item.groups.length"
       class="header--menu__item--link"
       href="{{::item.link}}"
       title="{{::item.name}}">
        {{::item.name}}
    </a>

    <div class="header-menu-dropdown ng-hide" ng-show="visible" ng-if=":: item.groups.length">
        <ul class="header-menu-dropdown__meganavGroup">
            <li ng-repeat="meganavGroup in item.groups" class="header--menu-group">
                <span class="meganav--group--name">{{::meganavGroup.name}}</span>
                <ul class="meganav--group--items">
                    <li ng-repeat="groupItem in meganavGroup.items">
                        <a href="{{::groupItem.link}}">{{::groupItem.name}}</a>
                        <span class="icon"></span>
                    </li>
                </ul>
            </li>

            <li class="header-menu-offers" ng-repeat="offer in item.offers">
                <a href="{{::offer.offer_link}}" class="placeholder">
                    <img tco-image="offer.offer_image" crop="3" alt="{{::offer.offer_name}}" />
                </a>
                <span class="offer-name">{{::offer.offer_name}}</span>
            </li>
        </ul>
        <div class="header-menu-message" ng-bind-html="item.message"></div>
    </div>
</li>

My issue is now that I cannot make out what where to find {{::item.name}}, which is the thing that I want to change. 现在的问题是,我无法确定在哪里可以找到{{:: item.name}},这是我想要更改的东西。 What technique can I use to find {{::item.name}}? 我可以使用什么技术来找到{{:: item.name}}?

Sorry for all the noob questions! 对不起所有菜鸟问题! Your help is much appreciated! 非常感谢您的帮助!

In Angular it is possible to build your own HTML element. 在Angular中,可以构建自己的HTML元素。 You won't find any information about this element because it doesn't exist. 您将找不到有关此元素的任何信息,因为它不存在。 The developer has created that on its own and handles the content inside a module. 开发人员自行创建了该内容,并处理了模块中的内容。 Have a look at http://www.aleaiactaest.ch/2012/07/29/build-your-own-html-element-with-angular/ for more information. 有关更多信息, 请访问http://www.aleaiactaest.ch/2012/07/29/build-your-own-html-element-with-angular/

Hope this helps, Cheers. 希望这会有所帮助,干杯。

As i've noticed it's Angular App, so probably there are defined an directive which is called meganavItem . 如我meganavItem ,它是Angular App,所以可能定义了一个名为meganavItem指令 See Angular Directive for more information, you have to find definition of that directive and discover what is html layout and logic lives under <meganav-item> . 有关更多信息,请参见Angular指令 。您必须找到该指令的定义,并发现<meganav-item>下的html布局和逻辑。 However if there are no directive with defined name. 但是,如果没有定义名称的指令。

Also it may be separate registered element, see "Custom Elements " article of how it's done and it would be more easy for you to find out how it works ( if it registered in that way...) 另外,它可能是单独的已注册元素,请参见“自定义元素”一文,了解其工作方式,这将使您更容易了解它的工作方式(如果它是以这种方式注册的...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM