【问题标题】:Running mmenu with a directive使用指令运行 mmenu
【发布时间】:2016-07-17 23:47:00
【问题描述】:

我是 angular 新手,并尝试使用 mmenu 创建指令,但不幸的是插件无法正常工作。 任何帮助都会很棒。

我创建了一个plunker

谢谢,

var App = angular.module('wdapp', []);

App.controller('results', function($scope, $http) {
 $http.get('data.json')
   .then(function(res){
      $scope.bookmarks = res.data;                
    });
});

App.directive("mmenu", function()
    {   
        return {
            restrict: "A",
            link: function(scope, element, attrs){
                $(element).mmenu({
                    offCanvas: false,
                    //counters: true,
                    searchfield: {
                        add: false,
                        //search: false,
                    },
                    header: {
                        add: true,
                        update: true,
                        title: "Navigation"
                    },
                    navbar: {
                        title: ""
                    },

                });
            }
        };
    });

【问题讨论】:

    标签: jquery angularjs mmenu


    【解决方案1】:

    我对@9​​87654322@ 了解不多,但根据您的笨拙,最明显的问题是您对restrict: 'A' 的使用。这适用于 attribute 指令。

    您需要将其更新为restrict: 'E'restrict: 'EA' 才能将其用作元素 指令;如你所愿:<mmenu></mmenu>

    有关restrict 属性的更多信息:AngularJS: API: $compile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 1970-01-01
      • 2020-04-18
      相关资源
      最近更新 更多