导出jQuery插件并导入为Angular中的模块并在指令中使用它?

时间:2019-05-03 03:14:00

标签: jquery angular plugins

我决定为angular 7创建一个插件作为示例代码:

(function ( $ ) {

    $.fn.greenify = function( options ) {

        // This is the easiest way to have default options.
        var settings = $.extend({
            // These are the defaults.
            color: "#556b2f",
            backgroundColor: "white"
        }, options );

        // Greenify the collection based on the settings variable.
        return this.css({
            color: settings.color,
            backgroundColor: settings.backgroundColor
        });

    };

}( jQuery ));

$( "div" ).greenify({
    color: "brown"
});

例如在上面的代码中, 1.如何导入成角模块? 2.如何在angular中将其用作指令(如何在angular模板中用作指令?)

我正在寻找指导。预先感谢。

看起来像这样使用:

import { MyPlugin } from 'MyPlugin';

在模板中: <div myplugin></div>-这样。

0 个答案:

没有答案