簡體   English   中英

所有站點的Angular運行jQuery代碼

[英]Angular run jQuery code for all site

我想在我的項目(基於AngularJS的項目)中實現http://areaaperta.com/nicescroll/

我需要做的是:

$(document).ready(

  function() { 

    $("html").niceScroll();

  }

);

但是,如果我需要它在整個站點中運行並且DOM完成加載后立即放置在哪里? 不知道指令是否是我所需要的,如果需要,它將如何?應該在哪里包含/運行它?

在有角項目中使用jquery插件的最佳方法是使用指令。

HTML:

…
<body ng-app="myApp" nicescroll>

</body>
…

JS:

…
var app = angular.module('myApp', []);

app.directive('nicescroll', function() {
    return {
        restrict: 'A',
        link: function() {
            // check, if the jquery plugin is loaded and available
            if ($.fn.niceScroll) {
                $('html').niceScroll();
            }
        }
    }
});
…

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM