AngularJS数据绑定对于Uploadcare.com无法正常工作

6

我正试图将一个上传脚本集成到我的网页中。我正在使用uploadcare.com。他们提供了一个简单的指令,但我无法让它起作用:

https://github.com/uploadcare/angular-uploadcare/blob/master/angular-uploadcare.js

我在设置ng-model="test",并且在我的控制器中有以下代码:
angular.module('testApp')
  .controller('MyCtrl', function ($scope) {
    $scope.test = "test";
  });

HTML代码如下所示:

这是 HTML 代码


<uploadcare-widget ng-model="test" data-public-key="xyz" />

当我检查 Firebug 时,我可以看到小部件在工作:
<input type="hidden" role="uploadcare-uploader" ng-model="test" data-public-key="6e0958899488d61fd5d0" data-crop="1200:630" value="http://www.ucarecdn.com/ca5513da-90f1-40d1-89e7-648237xxxxxx/-/crop/2560x1344/0,128/-/preview/" class="ng-isolate-scope ng-valid">

但是这个输入值从未被填充回我的"$scope.test"。为什么会这样呢?当我输出 $scope.test 时,它仍然显示 "test" 而不是我的图像路径值。

@yretuta 你是否使用了最新版本的指令?v0.1.0似乎没有正确处理数据绑定。请参考这个提交:https://github.com/uploadcare/angular-uploadcare/commit/c048f4651723366e7b163c8335567feedc2362a9 - Matthew Green
2个回答

2
你可以在Angular中使用$watch。
$scope.$watch('test', function(newValue, oldValue) {
    console.log($scope.test);
});

上传护理提供的功能。
$scope.onUCUploadComplete = function(info){
  console.log(info);
}; 

上传图片后的回调函数是什么?

1
请检查测试模型的范围。 您还可以像这样在指令内更新范围变量。
scope.test = $element.value()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接