【问题标题】:binding custom events in angularjs using directives使用指令在angularjs中绑定自定义事件
【发布时间】:2015-08-27 14:29:57
【问题描述】:

我正在尝试通过包装 jquery 自动完成插件来创建指令 像这样的

<input class="form-control" auto-complete ui-items="list" modvar="selectedSvr" callback="myfunction"/>

我想调用我传递给回调属性的任何函数,我该如何实现?

这是我的指令

app.directive('autoComplete', function() {
    return function($scope, iElement, iAttrs) {
        iElement.autocomplete({
            source: $scope[iAttrs.uiItems],
            select: function (event,ui) {
                $scope.$apply(function () {
                    $scope[iAttrs.modvar] = ui.item.value;
                    // maybe register/call myfunction here
                })
            }
        });
    };
});

【问题讨论】:

标签: javascript jquery angularjs jquery-ui


【解决方案1】:

我找到了解决方案here

现在代码看起来像

HTML

<input class="form-control" auto-complete ui-items="searchList" modvar="selectedItem" on-callback="callme()"/>

角度

app.directive('autoComplete', function() {
    return function ($scope, iElement, iAttrs) {
        iElement.autocomplete({
            source: $scope[iAttrs.uiItems],
            select: function (event,ui) {
                $scope.$apply(function () {
                    $scope[iAttrs.modvar] = ui.item.value;
                    $scope.$eval(iAttrs.onCallback);
                })
            }
        });
    };
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 2013-09-29
    • 2019-07-23
    • 2013-09-23
    • 1970-01-01
    • 2016-10-15
    相关资源
    最近更新 更多