仅在需要时创建单击处理程序

时间:2015-03-04 15:19:51

标签: javascript angularjs angularjs-directive jqlite

我有一个小指令,其中是一个按钮和一个隐藏的输入文件。

我想在单击按钮时创建一个单击处理程序,因此我会单击隐藏的输入文件。

我的指示:

app.directive('fileUpload', function($timeout) {
    return {
        restrict: 'E',
        templateUrl: "templates/partials/file-upload.html",

        controller: ['$scope', function ($scope) {

            $scope.fileInput = "";

            $scope.clickedImageUpload = function () {
                console.log($scope.fileInput);

                $scope.fileInput.click();
            };

        }],

        link: function(scope, element, attrs) {
            console.log(element);

            var fileInput = angular.element().find('.invisibleFileInput').html;
            scope.fileInput = element[0].getElementsByClassName('invisibleFileInput');
            console.log(scope.fileInput);
        }
    };
});

0 个答案:

没有答案