5

AngularJS と UniformJS を使用してアプリケーションを構築しています。選択したものをデフォルト値にリセットするリセットボタンをビューに付けたいと思います。uniform.js を使用すると、機能しません。

ここで調べることができます:

http://plnkr.co/edit/QYZRzlRf1qqAYgi8VbO6?p=preview

リセットボタンを連続してクリックしても何も起こりません。属性を削除すると、uniform.js を使用しなくなり、すべてが正しく動作します。

ありがとう

アップデート:

タイムアウトの使用が必要です。

app.controller('MainCtrl', function($scope, $timeout) {
  $scope.reset = function() {
    $scope.test = "";
    $timeout(jQuery.uniform.update, 0);
  };
});
4

3 に答える 3

1

@john-tsengの答えを少しだけ違うものにします。アプリケーションにはすでにかなりの数のチェックボックスがあるため、すべてのチェックボックスに新しい属性を適用したくありませんでした。これにより、no-uniform 属性を適用することで、特定のチェック ボックスに均一を適用しないようにするオプションも提供されます。

/*
 * Used to make sure that uniform.js works with angular by calling it's update method when the angular model value updates.
 */
app.directive('input', function ($timeout) {
    return {
        restrict: 'E',
        require: '?ngModel',
        link: function (scope, element, attr, ngModel) {
            if (attr.type === 'checkbox' && attr.ngModel && attr.noUniform === undefined) {
                element.uniform({ useID: false });
                scope.$watch(function () { return ngModel.$modelValue }, function () {
                    $timeout(jQuery.uniform.update, 0);
                });
            }
        }
    };
});
于 2015-04-23T00:33:20.803 に答える
0

ブローコードをお試しください。

    app.directive('applyUniform', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            if (!element.parents(".checker").length) {
                element.show().uniform();
                // update selected item check mark
                setTimeout(function () { $.uniform.update(); }, 300);
            }
        }
    };
});


<input apply-uniform   type="checkbox" ng-checked="vm.Message.Followers.indexOf(item.usrID) > -1"   ng-click="vm.toggleSelection(item.usrID)" />
于 2015-04-20T11:05:51.603 に答える