如何在ng-paste中粘贴文本?

时间:2015-04-17 18:47:44

标签: angularjs

我试图在输入文本中插入值:

Angular JS:

$scope.pasteYoutube = function (){
    $timeout(function () {
        // get $scope.url from input
    });
}

HTML:

<input ng-paste="pasteYoutube()" ng-trim="true" ng-model="url" type="text" class="long-input">

但我得到underfined $scope.url

1 个答案:

答案 0 :(得分:0)

我的猜测是角度尚未处理输入。尝试添加超时值,默认值为0,以便立即执行该功能。

编辑:

变化

$timeout(function () {
    // get $scope.url from input
});

$timeout(function () {
    // get $scope.url from input
}, 10);

这将等待10毫秒让angular从输入中获取url。