Using jqueryUi.resizeable() with AngularJs

后端 未结 1 1381
盖世英雄少女心
盖世英雄少女心 2021-02-10 11:36

I have a DOM element in one of my templates that I want to make resizable using jqueryUi. The long and short is that I have a

element in my template cal
相关标签:
1条回答
  • 2021-02-10 12:21

    For such stuff, a directive is always the right way to go.
    To make an element resizable (with an optional callback), you should implement a directive like this:

    app.directive('resizable', function () {
        var resizableConfig = {...};
    
        return {
            restrict: 'A',
            scope: {
                callback: '&onResize'
            },
            link: function postLink(scope, elem) {
                elem.resizable(resizableConfig);
                elem.on('resizestop', function () {
                    if (scope.callback) scope.callback();
                });
            }
        };
    });
    

    Then, in the HTML:

    <div resizable on-resize="someFunction()">Hello, world !</div>
    

    If you need varying resizable configurations, you can pass that to the isolate scope using an attribute.


    See, also, this short demo.

    0 讨论(0)
提交回复
热议问题